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 ¶
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 ¶
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 ¶
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 ¶
func (x *DecFixedPointNumber) Abs() *DecFixedPointNumber
Abs returns the absolute number of x.
func (*DecFixedPointNumber) Add ¶
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 ¶
func (x *DecFixedPointNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) BigInt ¶
func (x *DecFixedPointNumber) BigInt() *big.Int
BigInt returns the *big.Int representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Cmp ¶
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 ¶
func (x *DecFixedPointNumber) DecFloatPoint() *DecFloatPointNumber
DecFloatPoint returns the DecFloatPointNumber representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Div ¶
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 ¶
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 ¶
func (x *DecFixedPointNumber) Float() *FloatNumber
Float returns the Float representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Int ¶
func (x *DecFixedPointNumber) Int() *IntNumber
Int returns the Int representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Inv ¶
func (x *DecFixedPointNumber) Inv() *DecFixedPointNumber
Inv returns the inverse value of the number of x.
If x is zero, Inv panics.
func (*DecFixedPointNumber) MarshalBinary ¶
func (x *DecFixedPointNumber) MarshalBinary() (data []byte, err error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*DecFixedPointNumber) Mul ¶
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 ¶
func (x *DecFixedPointNumber) Neg() *DecFixedPointNumber
Neg returns the negative number of x.
func (*DecFixedPointNumber) Prec ¶
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 ¶
func (x *DecFixedPointNumber) RawBigInt() *big.Int
RawBigInt returns the internal *big.Int representation of the DecFixedPointNumber without scaling.
func (*DecFixedPointNumber) SetPrec ¶
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 ¶
func (x *DecFixedPointNumber) Sign() int
Sign returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*DecFixedPointNumber) String ¶
func (x *DecFixedPointNumber) String() string
String returns the 10-base string representation of the DecFixedPointNumber.
func (*DecFixedPointNumber) Sub ¶
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 ¶
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 ¶
func (x *DecFixedPointNumber) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type DecFloatPointNumber ¶
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 ¶
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 ¶
func (x *DecFloatPointNumber) Abs() *DecFloatPointNumber
Abs returns the absolute number of x.
func (*DecFloatPointNumber) Add ¶
func (x *DecFloatPointNumber) Add(y *DecFloatPointNumber) *DecFloatPointNumber
Add adds y to the number and returns the result.
func (*DecFloatPointNumber) BigFloat ¶
func (x *DecFloatPointNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) BigInt ¶
func (x *DecFloatPointNumber) BigInt() *big.Int
BigInt returns the *big.Int representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Cmp ¶
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 ¶
func (x *DecFloatPointNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPointNumber representation of the Float.
func (*DecFloatPointNumber) Div ¶
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 ¶
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 ¶
func (x *DecFloatPointNumber) Float() *FloatNumber
Float returns the Float representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Int ¶
func (x *DecFloatPointNumber) Int() *IntNumber
Int returns the Int representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Inv ¶
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 ¶
func (x *DecFloatPointNumber) MarshalBinary() (data []byte, err error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*DecFloatPointNumber) Mul ¶
func (x *DecFloatPointNumber) Mul(y *DecFloatPointNumber) *DecFloatPointNumber
Mul multiplies the number by y and returns the result.
func (*DecFloatPointNumber) Neg ¶
func (x *DecFloatPointNumber) Neg() *DecFloatPointNumber
Neg returns the negative number of x.
func (*DecFloatPointNumber) Prec ¶
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 ¶
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 ¶
func (x *DecFloatPointNumber) Sign() int
Sign returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*DecFloatPointNumber) String ¶
func (x *DecFloatPointNumber) String() string
String returns the 10-base string representation of the DecFloatPointNumber.
func (*DecFloatPointNumber) Sub ¶
func (x *DecFloatPointNumber) Sub(y *DecFloatPointNumber) *DecFloatPointNumber
Sub subtracts y from the number and returns the result.
func (*DecFloatPointNumber) Text ¶
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 ¶
func (x *DecFloatPointNumber) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type FloatNumber ¶
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 ¶
func (x *FloatNumber) Abs() *FloatNumber
Abs returns the absolute number of x.
func (*FloatNumber) Add ¶
func (x *FloatNumber) Add(y *FloatNumber) *FloatNumber
Add adds y to the number and returns the result.
func (*FloatNumber) BigFloat ¶
func (x *FloatNumber) BigFloat() *big.Float
BigFloat returns the *big.Float representation of the Float.
func (*FloatNumber) BigInt ¶
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 ¶
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 ¶
func (x *FloatNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPointNumber representation of the Float.
func (*FloatNumber) Div ¶
func (x *FloatNumber) Div(y *FloatNumber) *FloatNumber
Div divides the number by y and returns the result.
func (*FloatNumber) Int ¶
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 ¶
func (x *FloatNumber) Inv() *FloatNumber
Inv returns the inverse number of x.
func (*FloatNumber) IsInf ¶
func (x *FloatNumber) IsInf() bool
IsInf reports whether the number is an infinity.
func (*FloatNumber) Mul ¶
func (x *FloatNumber) Mul(y *FloatNumber) *FloatNumber
Mul multiplies the number by y and returns the result.
func (*FloatNumber) Neg ¶
func (x *FloatNumber) Neg() *FloatNumber
Neg returns the negative number of x.
func (*FloatNumber) Precision ¶
func (x *FloatNumber) Precision() uint
Precision returns the precision of the Float.
It is wrapper around big.Float.Prec.
func (*FloatNumber) SetPrecision ¶
func (x *FloatNumber) SetPrecision(prec uint) *FloatNumber
SetPrecision sets the precision of the Float.
It is wrapper around big.Float.SetPrec.
func (*FloatNumber) Sign ¶
func (x *FloatNumber) Sign() int
Sign returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*FloatNumber) Sqrt ¶
func (x *FloatNumber) Sqrt() *FloatNumber
Sqrt returns the square root of the number.
func (*FloatNumber) String ¶
func (x *FloatNumber) String() string
String returns the 10-base string representation of the Float.
func (*FloatNumber) Sub ¶
func (x *FloatNumber) Sub(y *FloatNumber) *FloatNumber
Sub subtracts y from the number and returns the result.
type IntNumber ¶
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) Cmp ¶
Cmp compares the number to y and returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
func (*IntNumber) DecFixedPoint ¶
func (x *IntNumber) DecFixedPoint(n uint8) *DecFixedPointNumber
DecFixedPoint returns the DecFixedPoint representation of the Int.
func (*IntNumber) DecFloatPoint ¶
func (x *IntNumber) DecFloatPoint() *DecFloatPointNumber
DecFloatPoint returns the DecFloatPoint representation of the Int.
func (*IntNumber) DivRoundUp ¶
DivRoundUp divides the number by y and returns the result rounded up.
func (*IntNumber) Float ¶
func (x *IntNumber) Float() *FloatNumber
Float returns the Float representation of the Int.