f128

package
v1.80.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2022 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T fixed.Dx, TO xmath.Numeric](f Int[T]) TO

As returns the equivalent value in the destination type.

func CheckedAs

func CheckedAs[T fixed.Dx, TO xmath.Numeric](f Int[T]) (TO, error)

CheckedAs is the same as As(), except that it returns an error if the value cannot be represented exactly in the requested destination type.

func MaxDecimalDigits

func MaxDecimalDigits[T fixed.Dx]() int

MaxDecimalDigits returns the maximum number of digits after the decimal that will be used.

Types

type Fraction added in v1.71.0

type Fraction[T fixed.Dx] struct {
	Numerator   Int[T]
	Denominator Int[T]
}

Fraction holds a fractional value.

func NewFraction added in v1.71.0

func NewFraction[T fixed.Dx](s string) Fraction[T]

NewFraction creates a new fractional value from a string.

func (Fraction[T]) MarshalJSON added in v1.71.0

func (f Fraction[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Fraction[T]) Normalize added in v1.71.0

func (f *Fraction[T]) Normalize()

Normalize the fraction, eliminating any division by zero and ensuring a positive denominator.

func (Fraction[T]) String added in v1.71.0

func (f Fraction[T]) String() string

func (Fraction[T]) StringWithSign added in v1.71.0

func (f Fraction[T]) StringWithSign() string

StringWithSign returns the same as String(), but prefixes the value with a '+' if it is positive.

func (*Fraction[T]) UnmarshalJSON added in v1.71.0

func (f *Fraction[T]) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (Fraction[T]) Value added in v1.71.0

func (f Fraction[T]) Value() Int[T]

Value returns the computed value.

type Int

type Int[T fixed.Dx] struct {
	// contains filtered or unexported fields
}

Int holds a fixed-point value. Values are truncated, not rounded.

func From

func From[T fixed.Dx, FROM xmath.Numeric](value FROM) Int[T]

From creates a new value.

func FromString

func FromString[T fixed.Dx](str string) (Int[T], error)

FromString creates a new value from a string.

func FromStringForced

func FromStringForced[T fixed.Dx](str string) Int[T]

FromStringForced creates a new value from a string.

func MaxSafeMultiply

func MaxSafeMultiply[T fixed.Dx]() Int[T]

MaxSafeMultiply returns the maximum value that can be safely multiplied without overflow.

func Maximum

func Maximum[T fixed.Dx]() Int[T]

Maximum returns the maximum possible value the type can hold.

func Minimum

func Minimum[T fixed.Dx]() Int[T]

Minimum returns the minimum possible value the type can hold.

func Multiplier

func Multiplier[T fixed.Dx]() Int[T]

Multiplier returns the multiplier used.

func (Int[T]) Abs

func (f Int[T]) Abs() Int[T]

Abs returns the absolute value of this value.

func (Int[T]) Add

func (f Int[T]) Add(value Int[T]) Int[T]

Add adds this value to the passed-in value, returning a new value.

func (Int[T]) Ceil

func (f Int[T]) Ceil() Int[T]

Ceil returns the value rounded up to the nearest whole number.

func (Int[T]) Cmp

func (f Int[T]) Cmp(n Int[T]) int

Cmp returns 1 if i > n, 0 if i == n, and -1 if i < n.

func (Int[T]) Comma

func (f Int[T]) Comma() string

Comma returns the same as String(), but with commas for values of 1000 and greater.

func (Int[T]) CommaWithSign

func (f Int[T]) CommaWithSign() string

CommaWithSign returns the same as Comma(), but prefixes the value with a '+' if it is positive.

func (Int[T]) Dec

func (f Int[T]) Dec() Int[T]

Dec returns the value decremented by 1.

func (Int[T]) Div

func (f Int[T]) Div(value Int[T]) Int[T]

Div divides this value by the passed-in value, returning a new value.

func (Int[T]) Equal

func (f Int[T]) Equal(n Int[T]) bool

Equal returns true if i == n.

func (Int[T]) GreaterThan

func (f Int[T]) GreaterThan(n Int[T]) bool

GreaterThan returns true if i > n.

func (Int[T]) GreaterThanOrEqual

func (f Int[T]) GreaterThanOrEqual(n Int[T]) bool

GreaterThanOrEqual returns true if i >= n.

func (Int[T]) Inc

func (f Int[T]) Inc() Int[T]

Inc returns the value incremented by 1.

func (Int[T]) LessThan

func (f Int[T]) LessThan(n Int[T]) bool

LessThan returns true if i < n.

func (Int[T]) LessThanOrEqual

func (f Int[T]) LessThanOrEqual(n Int[T]) bool

LessThanOrEqual returns true if i <= n.

func (Int[T]) MarshalJSON

func (f Int[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Int[T]) MarshalText

func (f Int[T]) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Int[T]) MarshalYAML

func (f Int[T]) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler.

func (Int[T]) Max

func (f Int[T]) Max(value Int[T]) Int[T]

Max returns the maximum of this value or its argument.

func (Int[T]) Min

func (f Int[T]) Min(value Int[T]) Int[T]

Min returns the minimum of this value or its argument.

func (Int[T]) Mod

func (f Int[T]) Mod(value Int[T]) Int[T]

Mod returns the remainder after subtracting all full multiples of the passed-in value.

func (Int[T]) Mul

func (f Int[T]) Mul(value Int[T]) Int[T]

Mul multiplies this value by the passed-in value, returning a new value.

func (Int[T]) Neg

func (f Int[T]) Neg() Int[T]

Neg negates this value, returning a new value.

func (Int[T]) Round

func (f Int[T]) Round() Int[T]

Round returns the nearest integer, rounding half away from zero.

func (Int[T]) String

func (f Int[T]) String() string

func (Int[T]) StringWithSign

func (f Int[T]) StringWithSign() string

StringWithSign returns the same as String(), but prefixes the value with a '+' if it is positive.

func (Int[T]) Sub

func (f Int[T]) Sub(value Int[T]) Int[T]

Sub subtracts the passed-in value from this value, returning a new value.

func (Int[T]) Trunc

func (f Int[T]) Trunc() Int[T]

Trunc returns a new value which has everything to the right of the decimal place truncated.

func (*Int[T]) UnmarshalJSON

func (f *Int[T]) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Int[T]) UnmarshalText

func (f *Int[T]) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Int[T]) UnmarshalYAML

func (f *Int[T]) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL