Documentation ¶
Index ¶
- Constants
- type DecFixedPointNumber
- func (x *DecFixedPointNumber) Abs() *DecFixedPointNumber
- func (x *DecFixedPointNumber) Add(y *DecFixedPointNumber) *DecFixedPointNumber
- func (x *DecFixedPointNumber) BigFloat() *big.Float
- func (x *DecFixedPointNumber) BigInt() *big.Int
- func (x *DecFixedPointNumber) Cmp(y *DecFixedPointNumber) int
- func (x *DecFixedPointNumber) DecFloatPoint() *DecFloatPointNumber
- func (x *DecFixedPointNumber) Div(y *DecFixedPointNumber) *DecFixedPointNumber
- func (x *DecFixedPointNumber) DivPrec(y *DecFixedPointNumber, prec uint32) *DecFixedPointNumber
- func (x *DecFixedPointNumber) Float() *FloatNumber
- func (x *DecFixedPointNumber) Int() *IntNumber
- func (x *DecFixedPointNumber) Inv() *DecFixedPointNumber
- func (x *DecFixedPointNumber) MarshalBinary() (data []byte, err error)
- func (x *DecFixedPointNumber) Mul(y *DecFixedPointNumber) *DecFixedPointNumber
- func (x *DecFixedPointNumber) Neg() *DecFixedPointNumber
- func (x *DecFixedPointNumber) Prec() uint8
- func (x *DecFixedPointNumber) RawBigInt() *big.Int
- func (x *DecFixedPointNumber) SetPrec(prec uint8) *DecFixedPointNumber
- func (x *DecFixedPointNumber) Sign() int
- func (x *DecFixedPointNumber) String() string
- func (x *DecFixedPointNumber) Sub(y *DecFixedPointNumber) *DecFixedPointNumber
- func (x *DecFixedPointNumber) Text(format byte, prec int) string
- func (x *DecFixedPointNumber) UnmarshalBinary(data []byte) error
- type DecFloatPointNumber
- func (x *DecFloatPointNumber) Abs() *DecFloatPointNumber
- func (x *DecFloatPointNumber) Add(y *DecFloatPointNumber) *DecFloatPointNumber
- func (x *DecFloatPointNumber) BigFloat() *big.Float
- func (x *DecFloatPointNumber) BigInt() *big.Int
- func (x *DecFloatPointNumber) Cmp(y *DecFloatPointNumber) int
- func (x *DecFloatPointNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
- func (x *DecFloatPointNumber) Div(y *DecFloatPointNumber) *DecFloatPointNumber
- func (x *DecFloatPointNumber) DivPrec(y *DecFloatPointNumber, prec uint32) *DecFloatPointNumber
- func (x *DecFloatPointNumber) Float() *FloatNumber
- func (x *DecFloatPointNumber) Int() *IntNumber
- func (x *DecFloatPointNumber) Inv() *DecFloatPointNumber
- func (x *DecFloatPointNumber) MarshalBinary() (data []byte, err error)
- func (x *DecFloatPointNumber) Mul(y *DecFloatPointNumber) *DecFloatPointNumber
- func (x *DecFloatPointNumber) Neg() *DecFloatPointNumber
- func (x *DecFloatPointNumber) Prec() uint8
- func (x *DecFloatPointNumber) SetPrec(n uint8) *DecFloatPointNumber
- func (x *DecFloatPointNumber) Sign() int
- func (x *DecFloatPointNumber) String() string
- func (x *DecFloatPointNumber) Sub(y *DecFloatPointNumber) *DecFloatPointNumber
- func (x *DecFloatPointNumber) Text(format byte, prec int) string
- func (x *DecFloatPointNumber) UnmarshalBinary(data []byte) error
- type FloatNumber
- func (x *FloatNumber) Abs() *FloatNumber
- func (x *FloatNumber) Add(y *FloatNumber) *FloatNumber
- func (x *FloatNumber) BigFloat() *big.Float
- func (x *FloatNumber) BigInt() *big.Int
- func (x *FloatNumber) Cmp(y *FloatNumber) int
- func (x *FloatNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
- func (x *FloatNumber) Div(y *FloatNumber) *FloatNumber
- func (x *FloatNumber) Int() *IntNumber
- func (x *FloatNumber) Inv() *FloatNumber
- func (x *FloatNumber) IsInf() bool
- func (x *FloatNumber) Mul(y *FloatNumber) *FloatNumber
- func (x *FloatNumber) Neg() *FloatNumber
- func (x *FloatNumber) Precision() uint
- func (x *FloatNumber) SetPrecision(prec uint) *FloatNumber
- func (x *FloatNumber) Sign() int
- func (x *FloatNumber) Sqrt() *FloatNumber
- func (x *FloatNumber) String() string
- func (x *FloatNumber) Sub(y *FloatNumber) *FloatNumber
- func (x *FloatNumber) Text(format byte, prec int) string
- type IntNumber
- func (x *IntNumber) Abs() *IntNumber
- func (x *IntNumber) Add(y *IntNumber) *IntNumber
- func (x *IntNumber) BigFloat() *big.Float
- func (x *IntNumber) BigInt() *big.Int
- func (x *IntNumber) Cmp(y *IntNumber) int
- func (x *IntNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
- func (x *IntNumber) DecFloatPoint() *DecFloatPointNumber
- func (x *IntNumber) Div(y *IntNumber) *IntNumber
- func (x *IntNumber) DivRoundUp(y *IntNumber) *IntNumber
- func (x *IntNumber) Float() *FloatNumber
- func (x *IntNumber) Lsh(n uint) *IntNumber
- func (x *IntNumber) Mul(y *IntNumber) *IntNumber
- func (x *IntNumber) Neg() *IntNumber
- func (x *IntNumber) Pow(y *IntNumber) *IntNumber
- func (x *IntNumber) Rem(y *IntNumber) *IntNumber
- func (x *IntNumber) Rsh(n uint) *IntNumber
- func (x *IntNumber) Sign() int
- func (x *IntNumber) Sqrt() *IntNumber
- func (x *IntNumber) String() string
- func (x *IntNumber) Sub(y *IntNumber) *IntNumber
- func (x *IntNumber) Text(base int) string
Constants ¶
const MaxDecPointPrecision = math.MaxUint8
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 fixed precision.
Internally, the number is stored as a *big.Int, scaled by 10^prec.
func DecFixedPoint ¶ added in v0.12.0
func DecFixedPoint(x any, n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPointNumber representation of x.
The argument x can be one of the following types: - IntNumber - FloatNumber - DecFixedPointNumber - DecFloatPointNumber - 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 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^prec.
func (*DecFixedPointNumber) Abs ¶ added in v0.12.0
func (x *DecFixedPointNumber) Abs() *DecFixedPointNumber
Abs returns the absolute number of x.
func (*DecFixedPointNumber) Add ¶ added in v0.12.0
func (x *DecFixedPointNumber) Add(y *DecFixedPointNumber) *DecFixedPointNumber
Add adds y to the number and returns the result.
Before the addition, the precision of x and y is increased to the larger of the two precisions. The precision of the result is set back to the precision of x.
func (*DecFixedPointNumber) BigFloat ¶ added in v0.12.0
func (x *DecFixedPointNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) BigInt ¶ added in v0.12.0
func (x *DecFixedPointNumber) BigInt() *big.Int
BigInt returns the *big.Int representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Cmp ¶ added in v0.12.0
func (x *DecFixedPointNumber) Cmp(y *DecFixedPointNumber) int
Cmp compares x and y and returns:
-1 if x < y 0 if x == y +1 if x > y
func (*DecFixedPointNumber) DecFloatPoint ¶ added in v0.16.1
func (x *DecFixedPointNumber) DecFloatPoint() *DecFloatPointNumber
DecFloatPoint returns the DecFloatPointNumber representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Div ¶ added in v0.12.0
func (x *DecFixedPointNumber) Div(y *DecFixedPointNumber) *DecFixedPointNumber
Div divides the number by y and returns the result.
Division by zero panics.
Before the division, the precision of x and y is increased to the precision of the larger of the two values plus decGuardDigits. The precision of the result is set back to the precision of x.
To use a different precision, use DivPrec.
func (*DecFixedPointNumber) DivPrec ¶ added in v0.16.1
func (x *DecFixedPointNumber) DivPrec(y *DecFixedPointNumber, prec uint32) *DecFixedPointNumber
DivPrec divides the number by y and returns the result.
Division by zero panics.
Before the division, the precision of x and y is increased to the given precision. The precision of the result is set back to the precision of x.
func (*DecFixedPointNumber) Float ¶ added in v0.12.0
func (x *DecFixedPointNumber) Float() *FloatNumber
Float returns the Float representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Int ¶ added in v0.12.0
func (x *DecFixedPointNumber) Int() *IntNumber
Int returns the Int representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Inv ¶ added in v0.16.1
func (x *DecFixedPointNumber) Inv() *DecFixedPointNumber
Inv returns the inverse value of the number of x.
If x is zero, Inv panics.
func (*DecFixedPointNumber) MarshalBinary ¶ added in v0.12.0
func (x *DecFixedPointNumber) MarshalBinary() (data []byte, err error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*DecFixedPointNumber) Mul ¶ added in v0.12.0
func (x *DecFixedPointNumber) Mul(y *DecFixedPointNumber) *DecFixedPointNumber
Mul multiplies the number by y and returns the result.
Before the multiplication, the precision of x and y is increased to the sum of the precisions of x and y. The precision of the result is set back to the precision of x.
func (*DecFixedPointNumber) Neg ¶ added in v0.12.0
func (x *DecFixedPointNumber) Neg() *DecFixedPointNumber
Neg returns the negative number of x.
func (*DecFixedPointNumber) Prec ¶ added in v0.16.1
func (x *DecFixedPointNumber) Prec() uint8
Prec returns the precision of the DecFixedPointNumber.
Prec is the number of decimal digits in the fractional part.
func (*DecFixedPointNumber) RawBigInt ¶ added in v0.12.0
func (x *DecFixedPointNumber) RawBigInt() *big.Int
RawBigInt returns the internal *big.Int representation of the DecFixedPointNumber without scaling.
func (*DecFixedPointNumber) SetPrec ¶ added in v0.16.1
func (x *DecFixedPointNumber) SetPrec(prec uint8) *DecFixedPointNumber
SetPrec returns a new DecFixedPointNumber with the given precision.
Prec is the number of decimal digits in the fractional part.
If precision is decreased, the number is rounded.
func (*DecFixedPointNumber) Sign ¶ added in v0.12.0
func (x *DecFixedPointNumber) Sign() int
Sign returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*DecFixedPointNumber) String ¶ added in v0.12.0
func (x *DecFixedPointNumber) String() string
String returns the 10-base string representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Sub ¶ added in v0.12.0
func (x *DecFixedPointNumber) Sub(y *DecFixedPointNumber) *DecFixedPointNumber
Sub subtracts y from the number and returns the result.
Before the subtraction, the precision of x and y is increased to the larger of the two precisions. The precision of the result is set back to the precision of x.
func (*DecFixedPointNumber) Text ¶ added in v0.12.0
func (x *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.
For any format other than 'f' and prec of -1, the result may be rounded.
func (*DecFixedPointNumber) UnmarshalBinary ¶ added in v0.12.0
func (x *DecFixedPointNumber) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type DecFloatPointNumber ¶ added in v0.16.1
type DecFloatPointNumber struct {
// contains filtered or unexported fields
}
DecFloatPointNumber represents a decimal floating-point number.
Unlike the DecFixedPointNumber, the precision of the DecFloatPointNumber is adjusted dynamically to fit the value.
func DecFloatPoint ¶ added in v0.16.1
func DecFloatPoint(x any) *DecFloatPointNumber
DecFloatPoint returns the DecFloatPointNumber representation of x.
The argument x can be one of the following types: - IntNumber - FloatNumber - DecFixedPointNumber - DecFloatPointNumber - 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 (*DecFloatPointNumber) Abs ¶ added in v0.16.1
func (x *DecFloatPointNumber) Abs() *DecFloatPointNumber
Abs returns the absolute number of x.
func (*DecFloatPointNumber) Add ¶ added in v0.16.1
func (x *DecFloatPointNumber) Add(y *DecFloatPointNumber) *DecFloatPointNumber
Add adds y to the number and returns the result.
func (*DecFloatPointNumber) BigFloat ¶ added in v0.16.1
func (x *DecFloatPointNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) BigInt ¶ added in v0.16.1
func (x *DecFloatPointNumber) BigInt() *big.Int
BigInt returns the *big.Int representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Cmp ¶ added in v0.16.1
func (x *DecFloatPointNumber) Cmp(y *DecFloatPointNumber) int
Cmp compares the number to y and returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*DecFloatPointNumber) DecFixedPoint ¶ added in v0.16.1
func (x *DecFloatPointNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPointNumber representation of the Float.
func (*DecFloatPointNumber) Div ¶ added in v0.16.1
func (x *DecFloatPointNumber) Div(y *DecFloatPointNumber) *DecFloatPointNumber
Div divides the number by y and returns the result.
Division by zero panics.
During division, the precision is increased by divPrecisionIncrease and then lowered to the smallest possible that still fits the result.
func (*DecFloatPointNumber) DivPrec ¶ added in v0.16.1
func (x *DecFloatPointNumber) DivPrec(y *DecFloatPointNumber, prec uint32) *DecFloatPointNumber
DivPrec divides the number by y and returns the result.
Division by zero panics.
During division, the precision is set to prec and then lowered to the smallest possible that still fits the result.
func (*DecFloatPointNumber) Float ¶ added in v0.16.1
func (x *DecFloatPointNumber) Float() *FloatNumber
Float returns the Float representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Int ¶ added in v0.16.1
func (x *DecFloatPointNumber) Int() *IntNumber
Int returns the Int representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Inv ¶ added in v0.16.1
func (x *DecFloatPointNumber) Inv() *DecFloatPointNumber
Inv returns the inverse value of the number of x.
If x is zero, Inv panics.
During inversion, the precision is increased by divPrecisionIncrease and then lowered to the smallest possible that still fits the result.
func (*DecFloatPointNumber) MarshalBinary ¶ added in v0.16.1
func (x *DecFloatPointNumber) MarshalBinary() (data []byte, err error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*DecFloatPointNumber) Mul ¶ added in v0.16.1
func (x *DecFloatPointNumber) Mul(y *DecFloatPointNumber) *DecFloatPointNumber
Mul multiplies the number by y and returns the result.
func (*DecFloatPointNumber) Neg ¶ added in v0.16.1
func (x *DecFloatPointNumber) Neg() *DecFloatPointNumber
Neg returns the negative number of x.
func (*DecFloatPointNumber) Prec ¶ added in v0.16.1
func (x *DecFloatPointNumber) Prec() uint8
Prec returns the precision of the DecFloatPointNumber.
Prec is the number of decimal digits in the fractional part.
func (*DecFloatPointNumber) SetPrec ¶ added in v0.16.1
func (x *DecFloatPointNumber) SetPrec(n uint8) *DecFloatPointNumber
SetPrec returns a new DecFloatPointNumber with the given precision.
Prec is the number of decimal digits in the fractional part.
func (*DecFloatPointNumber) Sign ¶ added in v0.16.1
func (x *DecFloatPointNumber) Sign() int
Sign returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*DecFloatPointNumber) String ¶ added in v0.16.1
func (x *DecFloatPointNumber) String() string
String returns the 10-base string representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Sub ¶ added in v0.16.1
func (x *DecFloatPointNumber) Sub(y *DecFloatPointNumber) *DecFloatPointNumber
Sub subtracts y from the number and returns the result.
func (*DecFloatPointNumber) Text ¶ added in v0.16.1
func (x *DecFloatPointNumber) 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.
For any format other than 'f' and prec of -1, the result may be rounded.
func (*DecFloatPointNumber) UnmarshalBinary ¶ added in v0.16.1
func (x *DecFloatPointNumber) 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 - DecFixedPointNumber - DecFloatPointNumber - 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 (x *FloatNumber) Abs() *FloatNumber
Abs returns the absolute number of x.
func (*FloatNumber) Add ¶ added in v0.10.2
func (x *FloatNumber) Add(y *FloatNumber) *FloatNumber
Add adds y to the number and returns the result.
func (*FloatNumber) BigFloat ¶ added in v0.10.2
func (x *FloatNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the Float.
func (*FloatNumber) BigInt ¶ added in v0.10.2
func (x *FloatNumber) BigInt() *big.Int
BigInt returns the *big.Int representation of the Float.
The fractional part is discarded and the number is rounded.
func (*FloatNumber) Cmp ¶ added in v0.10.2
func (x *FloatNumber) Cmp(y *FloatNumber) int
Cmp compares the number to y and returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*FloatNumber) DecFixedPoint ¶ added in v0.12.0
func (x *FloatNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPointNumber representation of the Float.
func (*FloatNumber) Div ¶ added in v0.10.2
func (x *FloatNumber) Div(y *FloatNumber) *FloatNumber
Div divides the number by y and returns the result.
func (*FloatNumber) Int ¶ added in v0.10.2
func (x *FloatNumber) Int() *IntNumber
Int returns the IntNumber representation of the Float.
The fractional part is discarded and the number is rounded.
func (*FloatNumber) Inv ¶ added in v0.10.2
func (x *FloatNumber) Inv() *FloatNumber
Inv returns the inverse number of x.
func (*FloatNumber) IsInf ¶ added in v0.10.2
func (x *FloatNumber) IsInf() bool
IsInf reports whether the number is an infinity.
func (*FloatNumber) Mul ¶ added in v0.10.2
func (x *FloatNumber) Mul(y *FloatNumber) *FloatNumber
Mul multiplies the number by y and returns the result.
func (*FloatNumber) Neg ¶ added in v0.10.2
func (x *FloatNumber) Neg() *FloatNumber
Neg returns the negative number of x.
func (*FloatNumber) Precision ¶ added in v0.16.1
func (x *FloatNumber) Precision() uint
Precision returns the precision of the Float.
It is wrapper around big.Float.Prec.
func (*FloatNumber) SetPrecision ¶ added in v0.16.1
func (x *FloatNumber) SetPrecision(prec uint) *FloatNumber
SetPrecision sets the precision of the Float.
It is wrapper around big.Float.SetPrec.
func (*FloatNumber) Sign ¶ added in v0.10.2
func (x *FloatNumber) Sign() int
Sign returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*FloatNumber) Sqrt ¶ added in v0.10.2
func (x *FloatNumber) Sqrt() *FloatNumber
Sqrt returns the square root of the number.
func (*FloatNumber) String ¶ added in v0.10.2
func (x *FloatNumber) String() string
String returns the 10-base string representation of the Float.
func (*FloatNumber) Sub ¶ added in v0.10.2
func (x *FloatNumber) Sub(y *FloatNumber) *FloatNumber
Sub subtracts y from the number and returns the result.
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 - DecFixedPointNumber - DecFloatPointNumber - big.Int - big.Float - int, int8, int16, int32, int64 - uint, uint8, uint16, uint32, uint64 - float32, float64 - string - a string accepted by big.Int.SetString, otherwise it returns nil - []byte - a byte slice accepted by big.Int.SetBytes, otherwise it returns nil
If the input value is not one of the supported types, nil is returned.
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 y and returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*IntNumber) DecFixedPoint ¶ added in v0.12.0
func (x *IntNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPoint representation of the Int.
func (*IntNumber) DecFloatPoint ¶ added in v0.16.1
func (x *IntNumber) DecFloatPoint() *DecFloatPointNumber
DecFloatPoint returns the DecFloatPoint representation of the Int.
func (*IntNumber) DivRoundUp ¶ added in v0.10.2
DivRoundUp divides the number by y and returns the result rounded up.
func (*IntNumber) Float ¶ added in v0.10.2
func (x *IntNumber) Float() *FloatNumber
Float returns the Float representation of the Int.
func (*IntNumber) Rem ¶ added in v0.10.2
Rem returns the remainder of the division of the number by y.
func (*IntNumber) String ¶ added in v0.10.2
String returns the 10-base string representation of the Int.