bn

package
v0.11.0-dev.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) 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) 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