bn

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

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

Abs returns the absolute number.

func (*DecFixedPointNumber) Add added in v0.12.0

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

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

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

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

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.

func (*FloatNumber) Text added in v0.10.2

func (f *FloatNumber) Text(format byte, prec int) string

Text returns the string representation of the Float. The format and prec arguments are the same as in big.Float.Text.

type IntNumber added in v0.10.2

type IntNumber struct {
	// contains filtered or unexported fields
}

IntNumber represents an arbitrary-precision integer.

func Int

func Int(x any) *IntNumber

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) Abs added in v0.10.2

func (i *IntNumber) Abs() *IntNumber

Abs returns the absolute number.

func (*IntNumber) Add added in v0.10.2

func (i *IntNumber) Add(x any) *IntNumber

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

func (i *IntNumber) BigFloat() *big.Float

BigFloat returns the *big.Float representation of the Int.

func (*IntNumber) BigInt added in v0.10.2

func (i *IntNumber) BigInt() *big.Int

BigInt returns the *big.Int representation of the Int.

func (*IntNumber) Cmp added in v0.10.2

func (i *IntNumber) 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 Int.

func (*IntNumber) DecFixedPoint added in v0.12.0

func (i *IntNumber) DecFixedPoint(n uint8) *DecFixedPointNumber

func (*IntNumber) Div added in v0.10.2

func (i *IntNumber) Div(x any) *IntNumber

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

func (i *IntNumber) DivRoundUp(x any) *IntNumber

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) Int64 added in v0.10.2

func (i *IntNumber) Int64() int64

Int64 returns the int64 representation of the Int.

func (*IntNumber) Lsh added in v0.10.2

func (i *IntNumber) Lsh(n uint) *IntNumber

Lsh returns the number shifted left by n bits.

func (*IntNumber) Mul added in v0.10.2

func (i *IntNumber) Mul(x any) *IntNumber

Mul multiplies the number by x and returns the result.

The x argument can be any of the types accepted by Int.

func (*IntNumber) Neg added in v0.10.2

func (i *IntNumber) Neg() *IntNumber

Neg returns the negative number.

func (*IntNumber) Pow added in v0.10.2

func (i *IntNumber) Pow(x any) *IntNumber

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

func (i *IntNumber) Rem(x any) *IntNumber

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) Rsh added in v0.10.2

func (i *IntNumber) Rsh(n uint) *IntNumber

Rsh returns the number shifted right by n bits.

func (*IntNumber) Sign added in v0.10.2

func (i *IntNumber) Sign() int

Sign returns:

-1 if i <  0
 0 if i == 0
+1 if i >  0

func (*IntNumber) Sqrt added in v0.10.2

func (i *IntNumber) Sqrt() *IntNumber

Sqrt returns the square root of the number.

func (*IntNumber) String added in v0.10.2

func (i *IntNumber) String() string

String returns the 10-base string representation of the Int.

func (*IntNumber) Sub added in v0.10.2

func (i *IntNumber) Sub(x any) *IntNumber

Sub subtracts x from the number and returns the result.

The x argument can be any of the types accepted by Int.

func (*IntNumber) Text added in v0.10.2

func (i *IntNumber) Text(base int) string

Text returns the string representation of the Int in the given base.

func (*IntNumber) Uint64 added in v0.10.2

func (i *IntNumber) Uint64() uint64

Uint64 returns the uint64 representation of the Int.

Jump to

Keyboard shortcuts

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