Documentation ¶
Index ¶
- type DecFixedPointNumber
- func (d *DecFixedPointNumber) Abs() *DecFixedPointNumber
- func (d *DecFixedPointNumber) Add(x any) *DecFixedPointNumber
- func (d *DecFixedPointNumber) BigFloat() *big.Float
- func (d *DecFixedPointNumber) BigInt() *big.Int
- func (d *DecFixedPointNumber) Cmp(x any) int
- func (d *DecFixedPointNumber) Div(x any) *DecFixedPointNumber
- func (d *DecFixedPointNumber) Float() *FloatNumber
- func (d *DecFixedPointNumber) Float64() float64
- func (d *DecFixedPointNumber) Int() *IntNumber
- func (d *DecFixedPointNumber) Int64() int64
- func (d *DecFixedPointNumber) MarshalBinary() (data []byte, err error)
- func (d *DecFixedPointNumber) Mul(x any) *DecFixedPointNumber
- func (d *DecFixedPointNumber) Neg() *DecFixedPointNumber
- func (d *DecFixedPointNumber) Precision() uint8
- func (d *DecFixedPointNumber) RawBigInt() *big.Int
- func (d *DecFixedPointNumber) SetPrecision(n uint8) *DecFixedPointNumber
- func (d *DecFixedPointNumber) Sign() int
- func (d *DecFixedPointNumber) String() string
- func (d *DecFixedPointNumber) Sub(x any) *DecFixedPointNumber
- func (d *DecFixedPointNumber) Text(format byte, prec int) string
- func (d *DecFixedPointNumber) Uint64() uint64
- func (d *DecFixedPointNumber) UnmarshalBinary(data []byte) error
- type FloatNumber
- func (f *FloatNumber) Abs() *FloatNumber
- func (f *FloatNumber) Add(x any) *FloatNumber
- func (f *FloatNumber) BigFloat() *big.Float
- func (f *FloatNumber) BigInt() *big.Int
- func (f *FloatNumber) Cmp(x any) int
- func (f *FloatNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
- func (f *FloatNumber) Div(x any) *FloatNumber
- func (f *FloatNumber) Float64() float64
- func (f *FloatNumber) Int() *IntNumber
- func (f *FloatNumber) Inv() *FloatNumber
- func (f *FloatNumber) IsInf() bool
- func (f *FloatNumber) Mul(x any) *FloatNumber
- func (f *FloatNumber) Neg() *FloatNumber
- func (f *FloatNumber) Sign() int
- func (f *FloatNumber) Sqrt() *FloatNumber
- func (f *FloatNumber) String() string
- func (f *FloatNumber) Sub(x any) *FloatNumber
- func (f *FloatNumber) Text(format byte, prec int) string
- type IntNumber
- func (i *IntNumber) Abs() *IntNumber
- func (i *IntNumber) Add(x any) *IntNumber
- func (i *IntNumber) BigFloat() *big.Float
- func (i *IntNumber) BigInt() *big.Int
- func (i *IntNumber) Cmp(x any) int
- func (i *IntNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
- func (i *IntNumber) Div(x any) *IntNumber
- func (i *IntNumber) DivRoundUp(x any) *IntNumber
- func (i *IntNumber) Float() *FloatNumber
- func (i *IntNumber) Int64() int64
- func (i *IntNumber) Lsh(n uint) *IntNumber
- func (i *IntNumber) Mul(x any) *IntNumber
- func (i *IntNumber) Neg() *IntNumber
- func (i *IntNumber) Pow(x any) *IntNumber
- func (i *IntNumber) Rem(x any) *IntNumber
- func (i *IntNumber) Rsh(n uint) *IntNumber
- func (i *IntNumber) Sign() int
- func (i *IntNumber) Sqrt() *IntNumber
- func (i *IntNumber) String() string
- func (i *IntNumber) Sub(x any) *IntNumber
- func (i *IntNumber) Text(base int) string
- func (i *IntNumber) Uint64() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DecFixedPointNumber ¶ added in v0.12.0
type DecFixedPointNumber struct {
// contains filtered or unexported fields
}
DecFixedPointNumber represents a fixed-point decimal number with precision. Internally, the number is stored as a *big.Int, scaled by 10^n.
func DecFixedPoint ¶ added in v0.12.0
func DecFixedPoint(x any, n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPoint DecFixedPointNumber of x.
func DecFixedPointFromRawBigInt ¶ added in v0.12.0
func DecFixedPointFromRawBigInt(x *big.Int, n uint8) *DecFixedPointNumber
DecFixedPointFromRawBigInt returns the DecFixedPointNumber of x assuming it is already scaled by 10^n.
func (*DecFixedPointNumber) Abs ¶ added in v0.12.0
func (d *DecFixedPointNumber) Abs() *DecFixedPointNumber
Abs returns the absolute number.
func (*DecFixedPointNumber) Add ¶ added in v0.12.0
func (d *DecFixedPointNumber) Add(x any) *DecFixedPointNumber
Add adds x to the number and returns the result.
The x argument can be any of the types accepted by DecFixedPointNumber.
func (*DecFixedPointNumber) BigFloat ¶ added in v0.12.0
func (d *DecFixedPointNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) BigInt ¶ added in v0.12.0
func (d *DecFixedPointNumber) BigInt() *big.Int
BigInt returns the *big.Int representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Cmp ¶ added in v0.12.0
func (d *DecFixedPointNumber) Cmp(x any) int
Cmp compares the number to x and returns:
-1 if i < x 0 if i == x +1 if i > x
The x argument can be any of the types accepted by DecFixedPointNumber.
func (*DecFixedPointNumber) Div ¶ added in v0.12.0
func (d *DecFixedPointNumber) Div(x any) *DecFixedPointNumber
Div divides the number by x and returns the result.
Division by zero panics.
The x argument can be any of the types accepted by DecFixedPointNumber.
func (*DecFixedPointNumber) Float ¶ added in v0.12.0
func (d *DecFixedPointNumber) Float() *FloatNumber
Float returns the Float representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Float64 ¶ added in v0.12.0
func (d *DecFixedPointNumber) Float64() float64
Float64 returns the float64 representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Int ¶ added in v0.12.0
func (d *DecFixedPointNumber) Int() *IntNumber
Int returns the Int representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Int64 ¶ added in v0.12.0
func (d *DecFixedPointNumber) Int64() int64
Int64 returns the int64 representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) MarshalBinary ¶ added in v0.12.0
func (d *DecFixedPointNumber) MarshalBinary() (data []byte, err error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*DecFixedPointNumber) Mul ¶ added in v0.12.0
func (d *DecFixedPointNumber) Mul(x any) *DecFixedPointNumber
Mul multiplies the number by x and returns the result.
The x argument can be any of the types accepted by DecFixedPointNumber.
func (*DecFixedPointNumber) Neg ¶ added in v0.12.0
func (d *DecFixedPointNumber) Neg() *DecFixedPointNumber
Neg returns the negative number.
func (*DecFixedPointNumber) Precision ¶ added in v0.12.0
func (d *DecFixedPointNumber) Precision() uint8
func (*DecFixedPointNumber) RawBigInt ¶ added in v0.12.0
func (d *DecFixedPointNumber) RawBigInt() *big.Int
RawBigInt returns the *big.Int representation of the number without scaling.
func (*DecFixedPointNumber) SetPrecision ¶ added in v0.12.0
func (d *DecFixedPointNumber) SetPrecision(n uint8) *DecFixedPointNumber
func (*DecFixedPointNumber) Sign ¶ added in v0.12.0
func (d *DecFixedPointNumber) Sign() int
Sign returns:
-1 if i < 0 0 if i == 0 +1 if i > 0
func (*DecFixedPointNumber) String ¶ added in v0.12.0
func (d *DecFixedPointNumber) String() string
String returns the 10-base string representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Sub ¶ added in v0.12.0
func (d *DecFixedPointNumber) Sub(x any) *DecFixedPointNumber
Sub subtracts x from the number and returns the result.
The x argument can be any of the types accepted by DecFixedPointNumber.
func (*DecFixedPointNumber) Text ¶ added in v0.12.0
func (d *DecFixedPointNumber) Text(format byte, prec int) string
Text returns the string representation of the DecFixedPointNumber. The format and prec arguments are the same as in big.Float.Text.
func (*DecFixedPointNumber) Uint64 ¶ added in v0.12.0
func (d *DecFixedPointNumber) Uint64() uint64
Uint64 returns the uint64 representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) UnmarshalBinary ¶ added in v0.12.0
func (d *DecFixedPointNumber) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type FloatNumber ¶ added in v0.10.2
type FloatNumber struct {
// contains filtered or unexported fields
}
FloatNumber represents a floating-point number.
func Float ¶
func Float(x any) *FloatNumber
Float returns the FloatNumber representation of x.
The argument x can be one of the following types:
- IntNumber
- FloatNumber
- big.Int
- big.Float
- int, int8, int16, int32, int64
- uint, uint8, uint16, uint32, uint64
- float32, float64
- string - a string accepted by big.Float.SetString, otherwise it returns nil
If the input value is not one of the supported types, nil is returned.
func (*FloatNumber) Abs ¶ added in v0.10.2
func (f *FloatNumber) Abs() *FloatNumber
Abs returns the absolute value of the number.
func (*FloatNumber) Add ¶ added in v0.10.2
func (f *FloatNumber) Add(x any) *FloatNumber
Add adds x to the number and returns the result.
The x argument can be any of the types accepted by Float.
func (*FloatNumber) BigFloat ¶ added in v0.10.2
func (f *FloatNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the Float.
func (*FloatNumber) BigInt ¶ added in v0.10.2
func (f *FloatNumber) BigInt() *big.Int
BigInt returns the *big.Int representation of the Float. The fractional part is discarded.
func (*FloatNumber) Cmp ¶ added in v0.10.2
func (f *FloatNumber) Cmp(x any) int
Cmp compares the number with x and returns:
-1 if x < y 0 if x == y (incl. -0 == 0, -Inf == -Inf, and +Inf == +Inf) +1 if x > y
The x argument can be any of the types accepted by Float.
func (*FloatNumber) DecFixedPoint ¶ added in v0.12.0
func (f *FloatNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPointNumber representation of the Float.
func (*FloatNumber) Div ¶ added in v0.10.2
func (f *FloatNumber) Div(x any) *FloatNumber
Div divides the number by x and returns the result.
The x argument can be any of the types accepted by Float.
func (*FloatNumber) Float64 ¶ added in v0.10.2
func (f *FloatNumber) Float64() float64
Float64 returns the float64 representation of the Float.
func (*FloatNumber) Int ¶ added in v0.10.2
func (f *FloatNumber) Int() *IntNumber
Int returns the IntNumber representation of the Float. The fractional part is discarded.
func (*FloatNumber) Inv ¶ added in v0.10.2
func (f *FloatNumber) Inv() *FloatNumber
Inv returns the inverse value of the number.
func (*FloatNumber) IsInf ¶ added in v0.10.2
func (f *FloatNumber) IsInf() bool
IsInf reports whether the number is an infinity.
func (*FloatNumber) Mul ¶ added in v0.10.2
func (f *FloatNumber) Mul(x any) *FloatNumber
Mul multiplies the number by x and returns the result.
The x argument can be any of the types accepted by Float.
func (*FloatNumber) Neg ¶ added in v0.10.2
func (f *FloatNumber) Neg() *FloatNumber
Neg returns the negative value of the number.
func (*FloatNumber) Sign ¶ added in v0.10.2
func (f *FloatNumber) Sign() int
Sign returns:
-1 if f < 0 0 if f == 0 +1 if f > 0
func (*FloatNumber) Sqrt ¶ added in v0.10.2
func (f *FloatNumber) Sqrt() *FloatNumber
Sqrt returns the square root of the number.
func (*FloatNumber) String ¶ added in v0.10.2
func (f *FloatNumber) String() string
String returns the 10-base string representation of the Float.
func (*FloatNumber) Sub ¶ added in v0.10.2
func (f *FloatNumber) Sub(x any) *FloatNumber
Sub subtracts x from the number and returns the result.
The x argument can be any of the types accepted by Float.
type IntNumber ¶ added in v0.10.2
type IntNumber struct {
// contains filtered or unexported fields
}
IntNumber represents an arbitrary-precision integer.
func Int ¶
Int returns the IntNumber representation of x.
The argument x can be one of the following types:
- IntNumber
- FloatNumber - the fractional part is discarded
- big.Int
- big.Float - the fractional part is discarded
- int, int8, int16, int32, int64
- uint, uint8, uint16, uint32, uint64
- float32, float64 - the fractional part is discarded
- string - a string accepted by big.Int.SetString, otherwise it returns nil
- []byte - big-endian representation of the integer
If the input value is not one of the supported types, nil is returned.
func (*IntNumber) Add ¶ added in v0.10.2
Add adds x to the number and returns the result.
The x argument can be any of the types accepted by Int.
func (*IntNumber) BigFloat ¶ added in v0.10.2
BigFloat returns the *big.Float representation of the Int.
func (*IntNumber) Cmp ¶ added in v0.10.2
Cmp compares the number to x and returns:
-1 if i < x 0 if i == x +1 if i > x
The x argument can be any of the types accepted by Int.
func (*IntNumber) DecFixedPoint ¶ added in v0.12.0
func (i *IntNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
func (*IntNumber) Div ¶ added in v0.10.2
Div divides the number by x and returns the result.
The x argument can be any of the types accepted by Int.
func (*IntNumber) DivRoundUp ¶ added in v0.10.2
DivRoundUp divides the number by x and returns the result rounded up.
The x argument can be any of the types accepted by Int.
func (*IntNumber) Float ¶ added in v0.10.2
func (i *IntNumber) Float() *FloatNumber
Float returns the Float representation of the Int.
func (*IntNumber) Mul ¶ added in v0.10.2
Mul multiplies the number by x and returns the result.
The x argument can be any of the types accepted by Int.
func (*IntNumber) Pow ¶ added in v0.10.2
Pow returns the number raised to the power of x.
The x argument can be any of the types accepted by Int.
func (*IntNumber) Rem ¶ added in v0.10.2
Rem returns the remainder of the division of the number by x.
The x argument can be any of the types accepted by Int.
func (*IntNumber) String ¶ added in v0.10.2
String returns the 10-base string representation of the Int.
func (*IntNumber) Sub ¶ added in v0.10.2
Sub subtracts x from the number and returns the result.
The x argument can be any of the types accepted by Int.