rok::core::num::bigint
rok::core::num::bigint: int, the arbitrary-precision integer
(stdlib 2.1.2, 2.1.6, 2.1.7). #[keyword("int")] routes the type name
here; an unsuffixed literal in an int slot is built by
Int::from_i64 / Int::from_literal (refs-lang 1.6.3).
A value that fits i64 lives in small, anything larger is sign +
magnitude (IntMag, base-2^32 limbs). Results that fit i64 always
drop back to small, so == / hash stay a field compare (spec
2.1.2 keeps promoted values big; the difference is not observable).
Limb buffers are never written once in an Int, so copies share them
(int is Copy, 2.13.3).
add / sub / shifts / products / Knuth D / gcd are runtime kernels
(rokr/src/bignum.rs). Here: Burnikel-Ziegler division above BZ
limbs, Barrett above MU, divide-and-conquer radix conversion over
chunk^(2^i), small remainders from a product mod B^m - 1, and cached
NTT transforms for an operand multiplied many times.
Structs
Int
pub struct IntAn arbitrary-precision integer (spec 2.1.2). Write it int.
pub const fn new() -> IntZero.
pub const fn from_i64(n: i64) -> Intpub const fn from_i32(n: i32) -> Intpub const fn from_u64(n: u64) -> Intpub fn from_literal(s: str) -> IntAn integer literal's digits (
_,0x/0o/0ballowed): what an unsuffixed literal too big fori64in anintslot lowers to.pub fn parse_radix(s: str, radix: u32) -> Int | nonesin baseradix(2..=36): an optional sign, then digits of either case;noneotherwise. The grammar is the runtime's, the same the primitives'FromStrreads.pub fn to_str_radix(self, radix: u32) -> strThe digits in base
radix(2..=36, lowercase),-first when negative.pub const fn to_i32(self) -> i32 | nonepub const fn to_i64(self) -> i64 | nonepub const fn to_u64(self) -> u64 | nonepub fn to_f64(self) -> f64The nearest
f64(ties to even;±infpastf64::MAX).pub const fn is_zero(self) -> boolpub const fn is_negative(self) -> boolpub const fn is_positive(self) -> boolpub const fn signum(self) -> Int-1,0or1.pub const fn abs(self) -> Intpub const fn bit_length(self) -> u64Bits of
|self|without leading zeros (0 for zero; Python'sbit_length).pub fn pow(self, exp: u32) -> Intself^exp(square and multiply).pub fn modpow(self, exp: Int, m: Int) -> Intself^exp %% m: in0..mform > 0,m + 1..=0form < 0(the sign ofm, as%%). Panics ifmis zero orexpnegative.pub fn gcd(self, other: Int) -> IntThe greatest common divisor, never negative (
gcd(0, 0) == 0). A runtime kernel (half-gcd reductions, then Lehmer's algorithm) after one division that brings the operands to about the same length.pub fn lcm(self, other: Int) -> IntThe least common multiple, never negative (
0if either is).pub fn div_euclid(self, rhs: Int) -> IntThe quotient rounded so that
rem_euclidis never negative; panics on zero.pub fn rem_euclid(self, rhs: Int) -> IntThe remainder in
0..rhs.abs(); panics on zero.pub fn isqrt(self) -> Intfloor(sqrt(self)); panics on a negative number.
pub fn checked_isqrt(self) -> Int | nonefloor(sqrt(self)),
nonefor a negative number. Newton steps doubling the precision (the recursion of Python'smath.isqrt): each refines the root of the top2dbits from that of the top2ebits,e = d / 2.pub fn div_rem(self, rhs: Int) -> (Int, Int)(self / rhs, self % rhs)in one division (truncating, like/and%); panics on zero.
Trait implementations 36
impl Add for Intimpl Sub for Intimpl Mul for Intimpl Div for Intimpl Rem for Intimpl Modulo for Intimpl Neg for Intimpl BitAnd for Intimpl BitOr for Intimpl BitXor for Intimpl BitNot for Intimpl Shl<u32> for Intimpl Shr<u32> for Intimpl PartialEq for Intimpl Eq for Intimpl PartialOrd for Intimpl Ord for Intimpl Hash for Intimpl Clone for Intimpl Copy for Intimpl Default for Intimpl Zero for Intimpl One for Intimpl Display for Intimpl Debug for Intimpl FromStr for Intimpl From<i8> for Intimpl From<i16> for Intimpl From<i32> for Intimpl From<i64> for Intimpl From<isize> for Intimpl From<u8> for Intimpl From<u16> for Intimpl From<u32> for Intimpl From<u64> for Intimpl From<usize> for Int