bignumber

Arbitrary precision integers and floating point numbers for Nim.

Types

BigInt = ref object of RootObj
  sign*: bool
  limbs*: seq[int64]
BigFloat = ref object of RootObj
  intPart*: BigInt
  exp*: int

Lets

zero: BigInt = BigInt(sign: true, limbs: @[0'i64])

Procs

proc newBigInt(s: string; checkInput: bool = true): BigInt {...}{.
    raises: [ValueError], tags: [].}
Constructs a new BigInt object from a string.
proc newBigInt(a: int64): BigInt {...}{.raises: [], tags: [].}
Constructs a new BigInt object from int64.
proc newBigInt[T: int8 | uint8 | int16 | uint16 | int32 | uint32 | int](a: T): BigInt
Constructs a new BigInt object from int8|uint8|int16|uint16|int32|uint32|int.
proc newBigInt(a: uint64): BigInt {...}{.raises: [ValueError], tags: [].}
Constructs a new BigInt object from uint64.
proc `$`(x: BigInt): string {...}{.raises: [], tags: [].}
Converts a BigInt object to a string.
proc `>`(x, y: BigInt): bool {...}{.raises: [], tags: [].}
proc `>=`(x, y: BigInt): bool {...}{.raises: [], tags: [].}
proc `==`(x, y: BigInt): bool {...}{.raises: [], tags: [].}
proc `<=`(x, y: BigInt): bool {...}{.raises: [], tags: [].}
proc `<`(x, y: BigInt): bool {...}{.raises: [], tags: [].}
proc `!=`(x, y: BigInt): bool {...}{.raises: [], tags: [].}
proc `-`(x: BigInt): BigInt {...}{.raises: [], tags: [].}
Negates x.
proc abs(x: BigInt): BigInt {...}{.raises: [], tags: [].}
Absolute value of x.
proc max(x, y: BigInt): BigInt {...}{.raises: [], tags: [].}
proc min(x, y: BigInt): BigInt {...}{.raises: [], tags: [].}
proc `+`(x, y: BigInt): BigInt {...}{.raises: [], tags: [].}
Returns the sum of two BigInts.
proc `+`(x: BigInt; y: SomeInteger): BigInt
Returns the sum of a BigInt and an integer.
proc `+`(x: SomeInteger; y: BigInt): BigInt
Returns the sum of an integer and a BigInt.
proc `-`(x, y: BigInt): BigInt {...}{.raises: [], tags: [].}
Returns the difference of two BigInts.
proc `-`(x: BigInt; y: SomeInteger): BigInt
Returns the difference of a BigInt and an integer.
proc `-`(x: SomeInteger; y: BigInt): BigInt
Returns the difference of an integer and a BigInt.
proc `*`(x, y: BigInt): BigInt {...}{.raises: [], tags: [].}
Returns the product of two BigInts.
proc `*`(x: BigInt; y: SomeInteger): BigInt
Returns the product of a BigInt and an integer.
proc `*`(x: SomeInteger; y: BigInt): BigInt
Returns the product of an integer and a BigInt.
proc `+=`[T: SomeInteger | BigInt](x: var BigInt; y: T)
x is overwritten by x + y.
proc `-=`[T: SomeInteger | BigInt](x: var BigInt; y: T)
x is overwritten by x - y.
proc `*=`[T: SomeInteger | BigInt](x: var BigInt; y: T)
x is overwritten by x * y.
proc `^`(x: BigInt; y: SomeInteger): BigInt
Returns x to the yth power.
proc `^`(x, y: BigInt): BigInt {...}{.raises: [ValueError], tags: [].}
Returns x to the yth power.
proc setPrec(prec: int) {...}{.raises: [], tags: [].}
Set precision of BigFloat.
proc getPrec(): int {...}{.raises: [], tags: [].}
Get current precision of BigFloat.
proc newBigFloat(s: string; checkInput: bool = true): BigFloat {...}{.
    raises: [ValueError], tags: [].}
Constructs a new BigFloat object from a string.
proc newBigFloat(a: BigInt): BigFloat {...}{.raises: [], tags: [].}
Constructs a new BigFloat object from a BigInt.
proc newBigFloat(a: SomeInteger): BigFloat
Constructs a new BigFloat object from an integer.
proc `$`(x: BigFloat): string {...}{.raises: [], tags: [].}
Converts a BigFloat to a string.
proc `-`(x: BigFloat): BigFloat {...}{.raises: [], tags: [].}
Negates a BigFloat.
proc abs(x: BigFloat): BigFloat {...}{.raises: [], tags: [].}
Absolute value of a BigFloat.
proc `+`(x, y: BigFloat): BigFloat {...}{.raises: [ValueError], tags: [].}
Returns the sum of two BigFloats.
proc `+`[T: SomeInteger | BigInt](x: BigFloat; y: T): BigFloat
Returns the sum of a BigFloat and a BigInt or an integer.
proc `+`[T: SomeInteger | BigInt](x: T; y: BigFloat): BigFloat
Returns the sum of a BigInt or an integer and a BigFloat.
proc `-`(x, y: BigFloat): BigFloat {...}{.raises: [ValueError], tags: [].}
Returns the difference of two BigFloat.
proc `-`[T: SomeInteger | BigInt](x: BigFloat; y: T): BigFloat
Returns the difference of a BigFloat and a BigInt or an integer.
proc `-`[T: SomeInteger | BigInt](x: T; y: BigFloat): BigFloat
Returns the difference of a BigInt or an integer and a BigFloat.
proc `*`(x, y: BigFloat): BigFloat {...}{.raises: [], tags: [].}
Returns the product of two BigFloats.
proc `*`[T: SomeInteger | BigInt](x: BigFloat; y: T): BigFloat
Returns the product of a BigFloat and a BigInt or an integer.
proc `*`[T: SomeInteger | BigInt](x: T; y: BigFloat): BigFloat
Returns the product of a BigInt or an integer and a BigFloat.
proc `>`(x, y: BigFloat): bool {...}{.raises: [ValueError], tags: [].}
proc `>=`(x, y: BigFloat): bool {...}{.raises: [ValueError], tags: [].}
proc `==`(x, y: BigFloat): bool {...}{.raises: [ValueError], tags: [].}
proc `<=`(x, y: BigFloat): bool {...}{.raises: [ValueError], tags: [].}
proc `<`(x, y: BigFloat): bool {...}{.raises: [ValueError], tags: [].}
proc max(x, y: BigFloat): BigFloat {...}{.raises: [ValueError], tags: [].}
proc min(x, y: BigFloat): BigFloat {...}{.raises: [ValueError], tags: [].}
proc `/`(x, y: BigFloat): BigFloat {...}{.raises: [ValueError], tags: [].}
x divided by y.
proc `/`[T: SomeInteger | BigInt](x: BigFloat; y: T): BigFloat
x divided by y.
proc `/`[T: SomeInteger | BigInt](x: T; y: BigFloat): BigFloat
x divided by y.
proc `+=`[T: BigFloat | BigInt | SomeInteger](x: var BigFloat; y: T)
x is overwritten by x + y
proc `-=`[T: BigFloat | BigInt | SomeInteger](x: var BigFloat; y: T)
x is overwritten by x - y
proc `*=`[T: BigFloat | BigInt | SomeInteger](x: var BigFloat; y: T)
x is overwritten by x * y
proc `/=`[T: BigFloat | BigInt | SomeInteger](x: var BigFloat; y: T)
x is overwritten by x / y
proc sqrt(x: BigFloat): BigFloat {...}{.raises: [ValueError], tags: [].}
Square root of a BigFloat.
proc sqrt(x: BigInt): BigFloat {...}{.raises: [ValueError], tags: [].}
Returns square root of a BigInt as a BigFloat.
proc `^`(x: BigFloat; y: SomeInteger): BigFloat
Returns x to the yth power. Real number exponent is not supported.
proc `^`(x: BigFloat; y: BigInt): BigFloat {...}{.raises: [ValueError], tags: [].}
Returns x to the yth power. Real number exponent is not supported.
proc `div`(x, y: BigInt): BigInt {...}{.raises: [ValueError], tags: [].}
Returns the quotient of x by y.
proc `div`(x: BigInt; y: SomeInteger): BigInt
Returns the quotient of x by y.
proc `div`(x: SomeInteger; y: BigInt): BigInt
Returns the quotient of x by y.
proc `mod`(x, y: BigInt): BigInt {...}{.raises: [ValueError], tags: [].}
Returns the remainder of x by y.
proc `mod`(x: BigInt; y: SomeInteger): BigInt
Returns the remainder of x by y.
proc `mod`(x: SomeInteger; y: BigInt): BigInt
Returns the remainder of x by y.
proc divmod(x, y: BigInt): seq[BigInt] {...}{.raises: [ValueError], tags: [].}
Returns the seq @[x div y, x mod y]
proc divmod(x: BigInt; y: SomeInteger): seq[BigInt]
Returns the seq @[x div y, x mod y]
proc divmod(x: SomeInteger; y: BigInt): seq[BigInt]
Returns the seq @[x div y, x mod y]

Iterators

iterator `..`(x, y: BigInt): BigInt {...}{.raises: [], tags: [].}
iterator `..<`(x, y: BigInt): BigInt {...}{.raises: [], tags: [].}
iterator countup(x, y: BigInt; step: int = 1): BigInt {...}{.raises: [], tags: [].}
iterator countdown(x, y: BigInt; step: int = 1): BigInt {...}{.raises: [], tags: [].}