std/big
On this page
Index
- type
BigInt- method
BigInt.add - method
BigInt.sub - method
BigInt.mul - method
BigInt.quo - method
BigInt.rem - method
BigInt.quo_rem - method
BigInt.div - method
BigInt.mod - method
BigInt.div_mod - method
BigInt.exp - method
BigInt.gcd - method
BigInt.mod_inverse - method
BigInt.sqrt - method
BigInt.neg - method
BigInt.abs - method
BigInt.sign - method
BigInt.cmp - method
BigInt.cmp_abs - method
BigInt.lsh - method
BigInt.rsh - method
BigInt.and - method
BigInt.or - method
BigInt.xor - method
BigInt.and_not - method
BigInt.not - method
BigInt.bit - method
BigInt.bit_len - method
BigInt.trailing_zeros - method
BigInt.probably_prime - method
BigInt.text - method
BigInt.bytes - method
BigInt.fill_bytes - method
BigInt.to_int - method
BigInt.to_float - method
BigInt.display - method
BigInt.debug
- method
- type
BigErr- method
BigErr.display
- method
- fn
from_int - fn
parse - fn
from_bytes
Types
BigInt
struct BigInt {
key: List[Int]
} derive Eq, Ord, HashAn integer of any size. key encodes it so that the derived order is
the numeric one: zero is [0]; a number of n 64 bit limbs is n (-n when
negative), then its limbs from the most significant, each xor the sign
bit (xor 2^63 - 1 when negative). Build one with the functions below,
not a literal.
BigInt.add
fn (x: BigInt) add(y: BigInt) -> BigIntBigInt.sub
fn (x: BigInt) sub(y: BigInt) -> BigIntBigInt.mul
fn (x: BigInt) mul(y: BigInt) -> BigIntBigInt.quo
fn (x: BigInt) quo(y: BigInt) -> BigIntx / y truncated toward zero (Go’s Quo); a fault when y is 0.
BigInt.rem
fn (x: BigInt) rem(y: BigInt) -> BigIntx - y * x.quo(y), with x’s sign (Go’s Rem).
BigInt.quo_rem
fn (x: BigInt) quo_rem(y: BigInt) -> (BigInt, BigInt)BigInt.div
fn (x: BigInt) div(y: BigInt) -> BigIntEuclidean division (Go’s Div): the remainder is never negative.
BigInt.mod
fn (x: BigInt) mod(y: BigInt) -> BigIntx mod y in 0 to |y| - 1 (Go’s Mod).
BigInt.div_mod
fn (x: BigInt) div_mod(y: BigInt) -> (BigInt, BigInt)BigInt.exp
fn (x: BigInt) exp(y: BigInt, m: BigInt? = None) -> BigIntx to the y, mod |m| when m is given and not 0 (Go’s Exp): y <= 0 gives 1 without m; with m, a negative y uses x’s inverse mod m, a fault when there is none (Go returns nil).
BigInt.gcd
fn (x: BigInt) gcd(y: BigInt) -> BigIntThe greatest common divisor of |x| and |y|; 0 when both are 0.
BigInt.mod_inverse
fn (x: BigInt) mod_inverse(m: BigInt) -> BigInt?x’s inverse mod m, None when gcd(x, m) is not 1 (Go’s ModInverse).
BigInt.sqrt
fn (x: BigInt) sqrt() -> BigIntThe floor of the square root; a fault when x < 0.
BigInt.neg
fn (x: BigInt) neg() -> BigIntBigInt.abs
fn (x: BigInt) abs() -> BigIntBigInt.sign
fn (x: BigInt) sign() -> Int-1, 0, or 1.
BigInt.cmp
fn (x: BigInt) cmp(y: BigInt) -> Int-1, 0, or 1 as x <, ==, > y (also the operators).
BigInt.cmp_abs
fn (x: BigInt) cmp_abs(y: BigInt) -> IntBigInt.lsh
fn (x: BigInt) lsh(n: Int) -> BigIntx * 2^n; a fault when n < 0.
BigInt.rsh
fn (x: BigInt) rsh(n: Int) -> BigIntx / 2^n rounded toward negative infinity (Go’s Rsh); a fault when n < 0.
BigInt.and
fn (x: BigInt) and(y: BigInt) -> BigIntThe bitwise operations on two’s complement, as Go’s And, Or, Xor, AndNot, Not.
BigInt.or
fn (x: BigInt) or(y: BigInt) -> BigIntBigInt.xor
fn (x: BigInt) xor(y: BigInt) -> BigIntBigInt.and_not
fn (x: BigInt) and_not(y: BigInt) -> BigIntBigInt.not
fn (x: BigInt) not() -> BigIntBigInt.bit
fn (x: BigInt) bit(i: Int) -> IntBit i of x’s two’s complement (0 or 1); a fault when i < 0.
BigInt.bit_len
fn (x: BigInt) bit_len() -> IntThe length of |x| in bits; 0 for 0.
BigInt.trailing_zeros
fn (x: BigInt) trailing_zeros() -> IntThe number of zero bits below the lowest one of |x|; 0 for 0.
BigInt.probably_prime
fn (x: BigInt) probably_prime(n: Int) -> BoolWhether x is probably prime: n Miller-Rabin rounds with Go’s pseudorandom bases plus a Baillie-PSW test (Go’s ProbablyPrime); a fault when n < 0.
BigInt.text
fn (x: BigInt) text(base: Int = 10) -> Strx in base 2 to 62: digits, then a to z, then A to Z (Go’s Text); a fault for another base.
BigInt.bytes
fn (x: BigInt) bytes() -> Bytes|x| big-endian, no leading zeros (Go’s Bytes).
BigInt.fill_bytes
fn (x: BigInt) fill_bytes(len: Int) -> Bytes|x| big-endian in len bytes, zeros first; a fault when it does not fit (Go’s FillBytes).
BigInt.to_int
fn (x: BigInt) to_int() -> Int?x as an Int, None when it does not fit (Go’s IsInt64 and Int64).
BigInt.to_float
fn (x: BigInt) to_float() -> FloatThe Float nearest x (Go’s Float64; out of range is +Inf or -Inf).
BigInt.display
fn (x: BigInt) display() -> Strx in base 10.
BigInt.debug
fn (x: BigInt) debug() -> StrBigErr
struct BigErr {
msg: Str
}invalid number "12x" in base 10, invalid base 63 (Go’s SetString
reports only false).
BigErr.display
fn (e: BigErr) display() -> StrFunctions
from_int
fn from_int(n: Int) -> BigIntn (Go’s NewInt).
parse
fn parse(s: Str, base: Int = 10) -> BigInt ! BigErrThe number s in base 2 to 62 (Go’s SetString): an optional sign, then
digits; base 0 reads a 0b, 0o, 0, or 0x prefix and _ between digits.
from_bytes
fn from_bytes(b: Bytes) -> BigIntThe unsigned big-endian number b (Go’s SetBytes).
↑ index