pub struct BigInt { /* private fields */ }Expand description
An exact, arbitrary-precision integer.
Implementations§
Source§impl BigInt
impl BigInt
Sourcepub fn to_i64(&self) -> Option<i64>
pub fn to_i64(&self) -> Option<i64>
Narrow back to an i64 iff the value fits — the basis of the “downsize when
it provably fits” path the runtime uses to stay on the fast i64 repr.
pub fn is_zero(&self) -> bool
Sourcepub fn is_odd(&self) -> bool
pub fn is_odd(&self) -> bool
Parity (the low bit of the magnitude — sign does not change it). Zero is even.
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
Nearest f64 (lossy by nature — float semantics) for mixed int/float math.
pub fn is_negative(&self) -> bool
pub fn is_positive(&self) -> bool
Sourcepub fn div_rem(&self, other: &Self) -> Option<(Self, Self)>
pub fn div_rem(&self, other: &Self) -> Option<(Self, Self)>
Truncated division toward zero: returns (quotient, remainder) with
self = q*other + r and the remainder carrying the dividend’s sign — exactly
matching Rust/i64 / and %, so the wide type is a drop-in for the narrow.
None when other is zero.
Sourcepub fn parse_decimal(s: &str) -> Option<Self>
pub fn parse_decimal(s: &str) -> Option<Self>
Parse a base-10 integer (optional leading +/-). None on any non-digit.
Sourcepub fn pow(&self, exp: u32) -> BigInt
pub fn pow(&self, exp: u32) -> BigInt
self raised to a non-negative integer power, by exponentiation-by-squaring
(0^0 == 1). Exact and unbounded — 2.pow(63) is the value i64 cannot hold.
Sourcepub fn to_le_bytes(&self) -> (bool, Vec<u8>)
pub fn to_le_bytes(&self) -> (bool, Vec<u8>)
Sign + little-endian magnitude bytes — a compact, exact serialization (the
inverse of BigInt::from_le_bytes). The wire ships these instead of a
decimal string, so there is no base conversion and no precision question.
Sourcepub fn from_le_bytes(negative: bool, bytes: &[u8]) -> Self
pub fn from_le_bytes(negative: bool, bytes: &[u8]) -> Self
Reconstruct from a sign flag and little-endian magnitude bytes (length need not be a multiple of 8; trailing zero limbs are normalized away).