This module implements multi-precision arithmetic (big numbers). The following numeric types are supported:
- Int signed integers - Rat rational numbers
Procs are typically of the form:
proc op(z, x, y: Int): Int # similar for Rat
and implement operations z = x op y with the result as receiver; if it is one of the operands it may be overwritten (and its memory reused). To enable chaining of operations, the result is also returned. Procs returning a result other than Int or Rat take one of the operands as the receiver.
Procs
proc newInt(x: culong): Int {.raises: [Exception], tags: [RootEffect].}
- Allocates and returns a new Int set to x.
proc newInt(x: int = 0): Int {.raises: [Exception], tags: [RootEffect].}
- Allocates and returns a new Int set to x.
proc newInt(s: string; base: cint = 10): Int {.raises: [ValueError, Exception], tags: [RootEffect].}
- Allocates and returns a new Int set to s, interpreted in the given base.
proc clear(z: Int) {.raises: [], tags: [].}
-
Clears the allocated space used by the number.
This normally happens on a finalizer call, but if you want immediate deallocation you can call it.
proc clone(z: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns a clone of z.
proc digits(z: Int; base: range[(2.cint) .. (62.cint)] = 10): csize {. raises: [], tags: [].}
- Returns the size of z measured in number of digits in the given base. The sign of z is ignored, just the absolute value is used.
proc `$`(z: Int; base: cint = 10): string {.raises: [ValueError], tags: [].}
- The stringify operator for an Int argument. Returns z converted to a string in the given base.
proc set(z, x: Int): Int {.raises: [], tags: [].}
- Sets z to x and returns z.
proc set(z: Int; x: culong): Int {.raises: [], tags: [].}
- Sets z to x and returns z.
proc set(z: Int; x: int): Int {.raises: [], tags: [].}
- Sets z to x and returns z.
proc set(z: Int; s: string; base: cint = 10): Int {.raises: [ValueError], tags: [].}
- Sets z to the value of s, interpreted in the given base, and returns z.
proc swap(x: Int; y: Int) {.raises: [], tags: [].}
- Swaps the values x and y efficiently.
proc cmp(x, y: Int): cint {.raises: [], tags: [].}
-
Compares x and y and returns:
-1 if x < y 0 if x == y +1 if x > y
proc cmp(x: Int; y: culong): cint {.raises: [], tags: [].}
-
Compares x and y and returns:
-1 if x < y 0 if x == y +1 if x > y
proc cmp(x: Int; y: int): cint {.raises: [], tags: [].}
-
Compares x and y and returns:
-1 if x < y 0 if x == y +1 if x > y
proc `==`[](x: Int; y: int | culong | Int): bool
- Returns whether x equals y.
proc `==`[](x: int | culong; y: Int): bool
- Returns whether x equals y.
proc `<`[](x: Int; y: int | culong | Int): bool
- Returns whether x is less than y.
proc `<`[](x: int | culong; y: Int): bool
- Returns whether x is less than y.
proc `<=`[](x: Int; y: int | culong | Int): bool
- Returns whether x is less than or equal y.
proc `<=`[](x: int | culong; y: Int): bool
- Returns whether x is less than or equal y.
proc sign(x: Int): cint {.raises: [], tags: [].}
-
Allows faster testing for negative, zero, and positive. Returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
proc positive(x: Int): bool {.raises: [], tags: [].}
- Returns whether x is positive or zero.
proc negative(x: Int): bool {.raises: [], tags: [].}
- Returns whether x is negative.
proc isZero(x: Int): bool {.raises: [], tags: [].}
- Returns whether x is zero.
proc abs(z, x: Int): Int {.raises: [], tags: [].}
- Sets z to |x| (the absolute value of x) and returns z.
proc abs(x: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns the absolute value of x.
proc add(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z to the sum x+y and returns z.
proc add(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z to the sum x+y and returns z.
proc add(z, x: Int; y: int): Int {.raises: [Exception], tags: [RootEffect].}
- Sets z to the sum x+y and returns z.
proc `+`[](x: Int; y: int | culong | Int): Int
- Returns the sum x+y.
proc `+`[](x: int | culong; y: Int): Int
- Returns the sum x+y.
proc sub(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z to the difference x-y and returns z.
proc sub(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z to the difference x-y and returns z.
proc sub(z: Int; x: culong; y: Int): Int {.raises: [], tags: [].}
- Sets z to the difference x-y and returns z.
proc sub(z, x: Int; y: int): Int {.raises: [Exception], tags: [RootEffect].}
- Sets z to the difference x-y and returns z.
proc sub(z: Int; x: int; y: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Sets z to the difference x-y and returns z.
proc `-`[](x: Int; y: int | culong | Int): Int
- Returns the difference x-y.
proc `-`[](x: int | culong; y: Int): Int
- Returns the difference x-y.
proc addMul(z, x, y: Int): Int {.raises: [], tags: [].}
- Increments z by x times y.
proc addMul(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Increments z by x times y.
proc addMul(z, x: Int; y: int): Int {.raises: [Exception], tags: [RootEffect].}
- Increments z by x times y.
proc addMul[](z: Int; x: int | culong; y: Int): Int
- Increments z by x times y.
proc addMul[](z: Int; x: int | culong; y: int | culong): Int
- Increments z by x times y.
proc subMul(z, x, y: Int): Int {.raises: [], tags: [].}
- Decrements z by x times y.
proc subMul(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Decrements z by x times y.
proc subMul(z, x: Int; y: int): Int {.raises: [Exception], tags: [RootEffect].}
- Decrements z by x times y.
proc subMul[](z: Int; x: int | culong; y: Int): Int
- Decrements z by x times y.
proc subMul[](z: Int; x: int | culong; y: int | culong): Int
- Increments z by x times y.
proc inc[](z: Int; x: int | culong | Int)
- Increments z by x.
proc dec[](z: Int; x: int | culong | Int)
- Decrements z by x.
proc `+=`[](z: Int; x: int | culong | Int)
- Increments z by x.
proc `-=`[](z: Int; x: int | culong | Int)
- Decrements z by x.
proc mul(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z to the product x*y and returns z.
proc mul(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z to the product x*y and returns z.
proc mul(z, x: Int; y: int): Int {.raises: [], tags: [].}
- Sets z to the product x*y and returns z.
proc `*`[](x: Int; y: int | culong | Int): Int
- Returns the product x*y.
proc `*`[](x: int | culong; y: Int): Int
- Returns the product x*y.
proc `*=`[](z: Int; x: int | culong | Int)
proc `and`(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z = x bitwise-and y and returns z.
proc `and`(x, y: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns x bitwise-and y.
proc `and`[](x: Int; y: int | culong): Int
- Returns x bitwise-and y.
proc `and`[](x: int | culong; y: Int): Int
- Returns x bitwise-and y.
proc `or`(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z = x bitwise inclusive-or y and returns z.
proc `or`(x, y: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns x bitwise inclusive-or y.
proc `or`[](x: Int; y: int | culong): Int
- Returns x bitwise inclusive-or y.
proc `or`[](x: int | culong; y: Int): Int
- Returns x bitwise inclusive-or y.
proc `xor`(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z = x bitwise exclusive-or y and returns z.
proc `xor`(x, y: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns x bitwise exclusive-or y.
proc `xor`[](x: Int; y: int | culong): Int
- Returns x bitwise exclusive-or y.
proc `xor`[](x: int | culong; y: Int): Int
- Returns x bitwise exclusive-or y.
proc `not`(z, x: Int): Int {.raises: [], tags: [].}
- Sets z to the one's complement of x and returns z.
proc `not`(x: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns the one's complement of x.
proc odd(z: Int): bool {.raises: [], tags: [].}
- Returns whether z is odd.
proc even(z: Int): bool {.raises: [], tags: [].}
- Returns whether z is even.
proc `div`(z, x, y: Int): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the quotient x/y for y != 0 and returns z. div implements truncated division towards zero.
proc `div`(z, x: Int; y: culong): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the quotient x/y for y != 0 and returns z. div implements truncated division towards zero.
proc `div`(z, x: Int; y: int): Int {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Sets z to the quotient x/y for y != 0 and returns z. div implements truncated division towards zero.
proc `div`[](x: Int; y: int | culong | Int): Int
- Returns the quotient x/y for y != 0. div implements truncated division towards zero.
proc `div`[](x: int | culong; y: Int): Int
- Returns the quotient x/y for y != 0. div implements truncated division towards zero.
proc `mod`(z, x, y: Int): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the remainder x/y for y != 0 and returns z. mod implements truncated division towards zero.
proc `mod`(z, x: Int; y: culong): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the remainder x/y for y != 0 and returns z. mod implements truncated division towards zero.
proc `mod`(z, x: Int; y: int): Int {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Sets z to the remainder x/y for y != 0 and returns z. mod implements truncated division towards zero.
proc `mod`[](x: Int; y: int | culong | Int): Int
- Returns the remainder x/y for y != 0. mod implements truncated division towards zero.
proc `mod`[](x: int | culong; y: Int): Int
- Returns the remainder x/y for y != 0. mod implements truncated division towards zero.
proc modInverse(z, g, n: Int): bool {.raises: [], tags: [].}
- Computes the inverse of g modulo n and put the result in z. If the inverse exists, the return value is true and z will satisfy 0 < z < abs(n). If an inverse doesn't exist the return value is false and z is undefined. The behaviour of this proc is undefined when n is zero.
proc modInverse(g: Int; n: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Computes the inverse of g modulo n. If an inverse doesn't exist the return value is undefined. The behaviour of this proc is undefined when n is zero.
proc modInverse[](g: Int; n: int | culong): Int
- Computes the inverse of g modulo n. If an inverse doesn't exist the return value is undefined. The behaviour of this proc is undefined when n is zero.
proc modInverse[](g: int | culong; n: Int): Int
- Computes the inverse of g modulo n. If an inverse doesn't exist the return value is undefined. The behaviour of this proc is undefined when n is zero.
proc divMod(q, r, x, y: Int): tuple[q, r: Int] {.raises: [DivByZeroError], tags: [].}
- Sets q to the quotient and r to the remainder resulting from x/y for y != 0 and returns the tuple (q, r). divMod implements truncated division towards zero.
proc divMod(q, r, x: Int; y: culong): tuple[q, r: Int] {. raises: [DivByZeroError], tags: [].}
- Sets q to the quotient and r to the remainder resulting from x/y for y != 0 and returns the tuple (q, r). divMod implements truncated division towards zero.
proc divMod(q, r, x: Int; y: int): tuple[q, r: Int] {. raises: [DivByZeroError, Exception], tags: [RootEffect].}
proc divMod[](x: Int; y: int | culong | Int): tuple[q, r: Int]
- Returns a tuple consisting of the quotient and remainder resulting from x/y for y != 0. divMod implements truncated division towards zero.
proc divMod[](x: int | culong; y: Int): tuple[q, r: Int]
- Returns a tuple consisting of the quotient and remainder resulting from x/y for y != 0. divMod implements truncated division towards zero.
proc fdiv(z, x, y: Int): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the quotient x/y for y != 0 and returns z. fdiv implements truncated division towards negative infinity. The f stands for “floor”.
proc fdiv(z, x: Int; y: culong): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the quotient x/y for y != 0 and returns z. fdiv implements truncated division towards negative infinity. The f stands for “floor”.
proc fdiv(z, x: Int; y: int): Int {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Sets z to the quotient x/y for y != 0 and returns z. fdiv implements truncated division towards negative infinity. The f stands for “floor”.
proc fdiv[](x: Int; y: int | culong | Int): Int
- Returns the quotient x/y for y != 0. fdiv implements truncated division towards negative infinity. The f stands for “floor”.
proc fdiv[](x: int | culong; y: Int): Int
- Returns the quotient x/y for y != 0. fdiv implements truncated division towards negative infinity. The f stands for “floor”.
proc `//`[](x: Int; y: int | culong | Int): Int
- Returns the quotient x/y for y != 0. // implements truncated division towards negative infinity.
proc `//`[](x: int | culong; y: Int): Int
- Returns the quotient x/y for y != 0. // implements truncated division towards negative infinity.
proc fmod(z, x, y: Int): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the remainder x/y for y != 0 and returns z. fmod implements truncated division towards negative infinity. The f stands for “floor”.
proc fmod(z, x: Int; y: culong): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the remainder x/y for y != 0 and returns z. fmod implements truncated division towards negative infinity. The f stands for “floor”.
proc fmod(z, x: Int; y: int): Int {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Sets z to the remainder x/y for y != 0 and returns z. fmod implements truncated division towards negative infinity. The f stands for “floor”.
proc fmod[](x: Int; y: int | culong | Int): Int
- Returns the remainder x/y for y != 0. fmod implements truncated division towards negative infinity. The f stands for “floor”.
proc fmod[](x: int | culong; y: Int): Int
- Returns the remainder x/y for y != 0. fmod implements truncated division towards negative infinity. The f stands for “floor”.
proc `\\`[](x: Int; y: int | culong | Int): Int
- Returns the remainder x/y for y != 0. \ implements truncated division towards negative infinity.
proc `\\`[](x: int | culong; y: Int): Int
- Returns the remainder x/y for y != 0. \ implements truncated division towards negative infinity.
proc fdivMod(q, r, x, y: Int): tuple[q, r: Int] {.raises: [DivByZeroError], tags: [].}
- Sets q to the quotient and r to the remainder resulting from x/y for y != 0 and returns the tuple (q, r). fdivMod implements truncated division towards negative infinity. The f stands for “floor”.
proc fdivMod(q, r, x: Int; y: culong): tuple[q, r: Int] {. raises: [DivByZeroError], tags: [].}
- Sets q to the quotient and r to the remainder resulting from x/y for y != 0 and returns the tuple (q, r). fdivMod implements truncated division towards negative infinity. The f stands for “floor”.
proc fdivMod(q, r, x: Int; y: int): tuple[q, r: Int] {. raises: [DivByZeroError, Exception], tags: [RootEffect].}
proc fdivMod[](x: Int; y: int | culong | Int): tuple[q, r: Int]
- Returns a tuple consisting of the quotient and remainder resulting from x/y for y != 0. fdivMod implements truncated division towards negative infinity. The f stands for “floor”.
proc fdivMod[](x: int | culong; y: Int): tuple[q, r: Int]
- Returns a tuple consisting of the quotient and remainder resulting from x/y for y != 0. fdivMod implements truncated division towards negative infinity. The f stands for “floor”.
proc cdiv(z, x, y: Int): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the quotient x/y for y != 0 and returns z. cdiv implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdiv(z, x: Int; y: culong): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the quotient x/y for y != 0 and returns z. cdiv implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdiv(z, x: Int; y: int): Int {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Sets z to the quotient x/y for y != 0 and returns z. cdiv implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdiv[](x: Int; y: int | culong | Int): Int
- Returns the quotient x/y for y != 0. cdiv implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdiv[](x: int | culong; y: Int): Int
- Returns the quotient x/y for y != 0. cdiv implements truncated division towards positive infinity. The c stands for “ceil”.
proc cmod(z, x, y: Int): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the remainder x/y for y != 0 and returns z. cmod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cmod(z, x: Int; y: culong): Int {.raises: [DivByZeroError], tags: [].}
- Sets z to the remainder x/y for y != 0 and returns z. cmod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cmod(z, x: Int; y: int): Int {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Sets z to the remainder x/y for y != 0 and returns z. cmod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cmod[](x: Int; y: int | culong | Int): Int
- Returns the remainder x/y for y != 0. cmod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cmod[](x: int | culong; y: Int): Int
- Returns the remainder x/y for y != 0. cmod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdivMod(q, r, x, y: Int): tuple[q, r: Int] {.raises: [DivByZeroError], tags: [].}
- Sets q to the quotient and r to the remainder resulting from x/y for y != 0 and returns the tuple (q, r). cdivMod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdivMod(q, r, x: Int; y: culong): tuple[q, r: Int] {. raises: [DivByZeroError], tags: [].}
- Sets q to the quotient and r to the remainder resulting from x/y for y != 0 and returns the tuple (q, r). cdivMod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdivMod(q, r, x: Int; y: int): tuple[q, r: Int] {. raises: [DivByZeroError, Exception], tags: [RootEffect].}
proc cdivMod[](x: Int; y: int | culong | Int): tuple[q, r: Int]
- Returns a tuple consisting of the quotient and remainder resulting from x/y for y != 0. cdivMod implements truncated division towards positive infinity. The c stands for “ceil”.
proc cdivMod[](x: int | culong; y: Int): tuple[q, r: Int]
- Returns a tuple consisting of the quotient and remainder resulting from x/y for y != 0. cdivMod implements truncated division towards positive infinity. The c stands for “ceil”.
proc fac(z, x: Int): Int {.raises: [RangeError, Exception, DivByZeroError], tags: [RootEffect].}
- Sets z to the factorial of x and returns z.
proc fac(z: Int; x: culong): Int {.raises: [], tags: [].}
- Sets z to the factorial of x and returns z.
proc fac(z: Int; x: int): Int {.raises: [RangeError], tags: [].}
- Sets z to the factorial of x and returns z.
proc fac[](x: int | culong | Int): Int
- Returns the factorial of x.
proc mulRange[](z: Int; a: int | culong | Int; b: int | culong | Int): Int
- Sets z to the product of all values in the range [a, b] inclusively and returns z. If a > b (empty range), the result is 1.
proc mulRange[](a: int | culong | Int; b: int | culong | Int): Int
- Returns the product of all values in the range [a, b] inclusively. If a > b (empty range), the result is 1.
proc binom(z, n: Int; k: culong): Int {.raises: [], tags: [].}
- Sets z to the binomial coefficient of (n, k) and returns z.
proc binom(z: Int; n, k: culong): Int {.raises: [], tags: [].}
- Sets z to the binomial coefficient of (n, k) and returns z.
proc binom(n, k: Int): Int {.raises: [Exception, RangeError, DivByZeroError], tags: [RootEffect].}
- Returns the binomial coefficient of (n, k).
proc binom[](n: culong | Int; k: culong): Int
- Returns the binomial coefficient of (n, k).
proc binom[](n: int | culong; k: Int): Int
- Returns the binomial coefficient of (n, k).
proc binom(n: Int; k: int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns the binomial coefficient of (n, k).
proc bit(x: Int; i: culong): cint {.raises: [], tags: [].}
- Returns the value of the i'th bit of x.
proc setBit(z: Int; i: culong): Int {.raises: [], tags: [].}
- Sets the i`'th bit of z and returns the resulting Int.
proc clearBit(z: Int; i: culong): Int {.raises: [], tags: [].}
- Clears the i`'th bit of z and returns the resulting Int.
proc complementBit(z: Int; i: culong): Int {.raises: [], tags: [].}
- Complements the i`'th bit of z and returns the resulting Int.
proc bitLen(x: Int): csize {.raises: [], tags: [].}
- Returns the length of the absolute value of x in bits.
proc pow(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z to x raised to y and returns z. The case 0^0 yields 1.
proc pow(z: Int; x, y: culong): Int {.raises: [], tags: [].}
- Sets z to x raised to y and returns z. The case 0^0 yields 1.
proc pow[](x: culong | Int; y: culong): Int
- Returns x raised to y. The case 0^0 yields 1.
proc pow(x: int; y: culong): Int {.raises: [Exception], tags: [RootEffect].}
- Returns x raised to y. The case 0^0 yields 1.
proc `^`[](x: int | culong | Int; y: culong): Int
- Returns x raised to y. The case 0^0 yields 1.
proc exp(z, x: Int; y: culong; m: Int): Int {.raises: [], tags: [].}
- Sets z to (x raised to y) modulo m and returns z. If m == 0, z = x^y.
proc exp(x: Int; y: culong; m: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns (x raised to y) modulo m. If m == 0, z = x^y.
proc exp[](x: Int; y: culong; m: int | culong): Int
- Returns (x raised to y) modulo m. If m == 0, z = x^y.
proc exp[](x: int | culong; y: culong; m: Int): Int
- Returns (x raised to y) modulo m. If m == 0, z = x^y.
proc gcd(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z to the greatest common divisor of x and y and returns z.
proc gcd(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z to the greatest common divisor of x and y and returns z.
proc gcd(z, x: Int; y: int): Int {.raises: [Exception], tags: [RootEffect].}
- Sets z to the greatest common divisor of x and y and returns z.
proc gcd[](x: Int; y: int | culong | Int): Int
- Returns the greatest common divisor of x and y.
proc gcd[](x: int | culong; y: Int): Int
- Returns the greatest common divisor of x and y.
proc lcm(z, x, y: Int): Int {.raises: [], tags: [].}
- Sets z to the least common multiple of x and y and returns z.
proc lcm(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z to the least common multiple of x and y and returns z.
proc lcm(z, x: Int; y: int): Int {.raises: [Exception], tags: [RootEffect].}
- Sets z to the least common multiple of x and y and returns z.
proc lcm[](x: Int; y: int | culong | Int): Int
- Returns the least common multiple of x and y.
proc lcm[](x: int | culong; y: Int): Int
- Returns the least common multiple of x and y.
proc `shl`(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z the shift left operation of x and y and returns z.
proc `shl`(x: Int; y: culong): Int {.raises: [Exception], tags: [RootEffect].}
- Computes the shift left operation of x and y.
proc `shr`(z, x: Int; y: culong): Int {.raises: [], tags: [].}
- Sets z to the shift right operation of x and y.
proc `shr`(x: Int; y: culong): Int {.raises: [Exception], tags: [RootEffect].}
- Computes the shift right operation of x and y.
proc fitsCULong(x: Int): bool {.raises: [], tags: [].}
- Returns whether x fits in a culong.
proc fitsCLong(x: Int): bool {.raises: [], tags: [].}
- Returns whether x fits in a clong.
proc fitsInt(x: Int): bool {.raises: [], tags: [].}
- Returns whether x fits in an int.
proc toCULong(x: Int): culong {.raises: [], tags: [].}
- Returns the value of x as a culong. If x is too big to fit a culong then just the least significant bits that do fit are returned. The sign of x is ignored, only the absolute value is used. To find out if the value will fit, use the proc fitsCULong.
proc toCLong(x: Int): clong {.raises: [], tags: [].}
- If x fits into a clong returns the value of x. Otherwise returns the least significant part of x, with the same sign as x. If x is too big to fit in a clong, the returned result is probably not very useful. To find out if the value will fit, use the proc fitsCLong.
proc toInt(x: Int): int {.raises: [], tags: [].}
- If x fits into an int returns the value of x. Otherwise returns the least significant part of x, with the same sign as x. If x is too big to fit in an int, the returned result is probably not very useful. To find out if the value will fit, use the proc fitsInt.
proc neg(z, x: Int): Int {.raises: [], tags: [].}
- Sets z to -x and returns z.
proc `-`(x: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Unary - operator for an Int. Negates x.
proc probablyPrime(x: Int; n: cint): cint {.raises: [], tags: [].}
- Determines whether x is prime. Return 2 if x is definitely prime, return 1 if x is probably prime (without being certain), or return 0 if x is definitely composite. This proc does some trial divisions, then some Miller-Rabin probabilistic primality tests. The argument n controls how many such tests are done; a higher value will reduce the chances of a composite being returned as "probably prime". 25 is a reasonable number; a composite number will then be identified as a prime with a probability of less than 2^(-50).
proc nextPrime(z, x: Int): Int {.raises: [], tags: [].}
- Sets z to the next prime greater than x. This proc uses a probabilistic algorithm to identify primes. For practical purposes it's adequate, the chance of a composite passing will be extremely small.
proc nextPrime(x: Int): Int {.raises: [Exception], tags: [RootEffect].}
- Returns the next prime greater than x. This proc uses a probabilistic algorithm to identify primes. For practical purposes it's adequate, the chance of a composite passing will be extremely small.
proc newRat(): Rat {.raises: [Exception], tags: [RootEffect].}
- Creates a new Rat and set it to 0/1.
proc newRat(f: float): Rat {.raises: [ValueError, Exception], tags: [RootEffect].}
- Creates a new Rat and set it to the value of f. There is no rounding, this conversion is exact.
proc newRat(a, b: Int): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Creates a new Rat with numerator a and denominator b.
proc newRat(a, b: culong): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Creates a new Rat with numerator a and denominator b.
proc newRat(a: clong; b: culong): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Creates a new Rat with numerator a and denominator b.
proc newRat[](a: Int; b: int | culong): Rat
- Creates a new Rat with numerator a and denominator b.
proc newRat[](a: culong | int; b: Int): Rat
- Creates a new Rat with numerator a and denominator b.
proc newRat(a, b: int): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Creates a new Rat with numerator a and denominator b.
proc newRat(s: string; base: cint = 10): Rat {.raises: [ValueError, Exception], tags: [RootEffect].}
- Allocates and returns a new Rat set to s, interpreted in the given base.
proc newRat(x: Int): Rat {.raises: [Exception], tags: [RootEffect].}
- Creates a new Rat and set it to x/1.
proc newRat(x: culong): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Creates a new Rat and set it to x/1.
proc newRat(x: int): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Creates a new Rat and set it to x/1.
proc clear(z: Rat) {.raises: [], tags: [].}
-
Clears the allocated space used by the rational.
This normally happens on a finalizer call, but if you want immediate deallocation you can call it.
proc clone(z: Rat): Rat {.raises: [Exception], tags: [RootEffect].}
- Returns a clone of z.
proc `$`(z: Rat; base: range[(2.cint) .. (36.cint)] = 10): string {.raises: [], tags: [].}
- The stringify operator for a Rat argument. Returns z converted to a string in the given base.
proc num(x: Rat): Int {.raises: [Exception], tags: [RootEffect].}
- Returns the numerator of x.
proc denom(x: Rat): Int {.raises: [Exception], tags: [RootEffect].}
- Returns the denominator of x.
proc setNum[](z: Rat; x: int | culong | Int): Rat
- Sets the numerator of z to x and returns z.
proc setDenom[](z: Rat; x: int | culong | Int): Rat
- Sets the denominator of z to x and returns z.
proc set(z: Rat; x: Rat): Rat {.raises: [], tags: [].}
- Sets z to x and returns z.
proc set(z: Rat; x: float): Rat {.raises: [ValueError], tags: [].}
- Sets z to x and returns z.
proc set(z: Rat; a, b: Int): Rat {.raises: [DivByZeroError], tags: [].}
- Sets z to a/b and returns z.
proc set(z: Rat; a, b: culong): Rat {.raises: [DivByZeroError], tags: [].}
- Sets z to a/b and returns z.
proc set(z: Rat; a: clong; b: culong): Rat {.raises: [DivByZeroError], tags: [].}
- Sets z to a/b and returns z.
proc set[](z: Rat; a: Int; b: int | culong): Rat
- Sets z to a/b and returns z.
proc set[](z: Rat; a: culong | int; b: Int): Rat
- Sets z to a/b and returns z.
proc set(z: Rat; a, b: int): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Sets z to a/b and returns z.
proc set(z: Rat; x: Int): Rat {.raises: [], tags: [].}
- Creates a new Rat and set it to x/1.
proc set(z: Rat; x: culong): Rat {.raises: [DivByZeroError], tags: [].}
- Creates a new Rat and set it to x/1.
proc set(z: Rat; x: int): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Creates a new Rat and set it to x/1.
proc swap(x: Rat; y: Rat) {.raises: [], tags: [].}
- Swaps the values x and y efficiently.
proc cmp(x, y: Rat): cint {.raises: [], tags: [].}
-
Compares x and y and returns:
-1 if x < y 0 if x == y +1 if x > y
proc cmp(x: Rat; a, b: Int): cint {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
-
Compares x and a/b and returns:
-1 if x < a/b 0 if x == a/b +1 if x > a/b
proc cmp(x: Rat; a, b: culong): cint {.raises: [], tags: [].}
-
Compares x and a/b and returns:
-1 if x < a/b 0 if x == a/b +1 if x > a/b
proc cmp(x: Rat; a: clong; b: culong): cint {.raises: [], tags: [].}
-
Compares x and a/b and returns:
-1 if x < a/b 0 if x == a/b +1 if x > a/b
proc cmp[](x: Rat; a: Int; b: int | culong): cint
-
Compares x and a/b and returns:
-1 if x < a/b 0 if x == a/b +1 if x > a/b
proc cmp[](x: Rat; a: culong | int; b: Int): cint
-
Compares x and a/b and returns:
-1 if x < a/b 0 if x == a/b +1 if x > a/b
proc cmp(x: Rat; a, b: int): cint {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
-
Compares x and a/b and returns:
-1 if x < a/b 0 if x == a/b +1 if x > a/b
proc cmp[](x: Rat; y: culong | Int): cint
-
Compares x and y/1 and returns:
-1 if x < y 0 if x == y +1 if x > y
proc cmp(x: Rat; y: int): cint {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
-
Compares x and y/1 and returns:
-1 if x < y 0 if x == y +1 if x > y
proc `==`(x, y: Rat): bool {.raises: [], tags: [].}
- Returns whether x equals y.
proc `==`[](x: Rat; y: int | culong | Int): bool
- Returns whether x equals y.
proc `==`[](x: int | culong | Int; y: Rat): bool
- Returns whether x equals y.
proc `<`[](x: Rat; y: int | culong | Int | Rat): bool
- Returns whether x is less than y.
proc `<`[](x: int | culong | Int; y: Rat): bool
- Returns whether x is less than y.
proc `<=`[](x: Rat; y: int | culong | Int | Rat): bool
- Returns whether x is less than or equal y.
proc `<=`[](x: int | culong | Int; y: Rat): bool
- Returns whether x is less than or equal y.
proc sign(x: Rat): cint {.raises: [], tags: [].}
-
Allows faster testing for negative, zero, and positive. Returns:
-1 if x < 0 0 if x == 0 +1 if x > 0
proc positive(x: Rat): bool {.raises: [], tags: [].}
- Returns whether x is positive or zero.
proc negative(x: Rat): bool {.raises: [], tags: [].}
- Returns whether x is negative.
proc isZero(x: Rat): bool {.raises: [], tags: [].}
- Returns whether x is zero.
proc abs(z, x: Rat): Rat {.raises: [], tags: [].}
- Sets z to |x| (the absolute value of x) and returns z.
proc abs(x: Rat): Rat {.raises: [Exception], tags: [RootEffect].}
- Returns the absolute value of x.
proc add(z, x, y: Rat): Rat {.raises: [], tags: [].}
- Sets z to the sum x+y and returns z.
proc add[](z: Rat; x: Rat; y: int | culong | Int): Rat
- Sets z to the sum x+y and returns z.
proc `+`[](x: Rat; y: int | culong | Int | Rat): Rat
- Returns the sum x+y.
proc `+`[](x: int | culong | Int; y: Rat): Rat
- Returns the sum x+y.
proc sub(z, x, y: Rat): Rat {.raises: [], tags: [].}
- Sets z to the difference x.y and returns z.
proc sub[](z: Rat; x: Rat; y: int | culong | Int): Rat
- Sets z to the difference x.y and returns z.
proc `-`[](x: Rat; y: int | culong | Int | Rat): Rat
- Returns the difference x-y.
proc `-`[](x: int | culong | Int; y: Rat): Rat
- Returns the difference x-y.
proc inc[](z: Rat; x: int | culong | Int | Rat)
- Increments z by x.
proc dec[](z: Rat; x: int | culong | Int | Rat)
- Decrements z by x.
proc `+=`[](z: Rat; x: int | culong | Int | Rat)
- Increments z by x.
proc `-=`[](z: Rat; x: int | culong | Int | Rat)
- Decrements z by x.
proc mul(z, x, y: Rat): Rat {.raises: [], tags: [].}
- Sets z to the product x*y and returns z.
proc mul[](z: Rat; x: Rat; y: int | culong | Int): Rat
- Sets z to the product x*y and returns z.
proc `*`[](x: Rat; y: int | culong | Int | Rat): Rat
- Returns the product x*y.
proc `*`[](x: int | culong | Int; y: Rat): Rat
- Returns the product x*y.
proc `*=`[](z: Rat; x: int | culong | Int | Rat)
proc divide(z, x, y: Rat): Rat {.raises: [DivByZeroError], tags: [].}
- Sets z to the quotient x/y and returns z.
proc divide[](z: Rat; x: Rat; y: int | culong | Int): Rat
- Sets z to the quotient x/y and returns z.
proc divide[](z: Rat; x: int | culong | Int; y: Rat): Rat
- Sets z to the quotient x/y and returns z.
proc `/`[](x: Rat; y: int | culong | Int | Rat): Rat
- Returns the quotient x/y.
proc `/`[](x: int | culong | Int; y: Rat): Rat
- Returns the quotient x/y.
proc `/=`[](z: Rat; x: int | culong | Int | Rat)
proc `/`[](x: Int; y: int | culong | Int): Rat
- Returns a Rat with numerator x and denominator y.
proc `/`[](x: int | culong; y: Int): Rat
- Returns a Rat with numerator x and denominator y.
proc inv(z, x: Rat): Rat {.raises: [DivByZeroError], tags: [].}
- Sets z to 1/x and returns z.
proc reciprocal(x: Rat): Rat {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Returns 1/x.
proc toFloat(x: Rat): float {.raises: [], tags: [].}
- Returns the nearest float value for x.
proc toFloatExact(x: Rat): tuple[r: float, e: bool] {. raises: [ValueError, Exception], tags: [RootEffect].}
- Returns the nearest float value for x in r, and a bool in e indicating whether r represents x exactly.
proc isInt(x: Rat): bool {.raises: [], tags: [].}
- Returns whether the denominator of x is 1.
proc toInt(x: Rat): Int {.raises: [DivByZeroError, Exception], tags: [RootEffect].}
- Converts x to an Int. Conversion rounds towards zero if x does not contain an integer value.
proc neg(z, x: Rat): Rat {.raises: [], tags: [].}
- Sets z to -x and returns z.
proc `-`(x: Rat): Rat {.raises: [Exception], tags: [RootEffect].}
- Unary - operator for a Rat. Negates x.
Iterators
iterator countup[](a: Int; b: int | culong | Int; step: int | culong | Int): Int {. inline.}
- Counts from a up to b with the given step count.
iterator countup[](a: int | culong; b: Int; step: Int): Int {.inline.}
- Counts from a up to b with the given step count.
iterator countup[](a: int | culong; b: int | culong; step: Int): Int {.inline.}
- Counts from a up to b with the given step count.
iterator countup[](a: int | culong; b: Int; step: int | culong): Int {.inline.}
- Counts from a up to b with the given step count.
iterator `..`[](a: Int; b: int | culong | Int): Int {.inline.}
- An alias for countup.
iterator `..`[](a: int | culong; b: Int): Int {.inline.}
- An alias for countup.