pub struct BigInt { /* private fields */ }Expand description
An arbitrary-precision integer.
Implementations§
Source§impl BigInt
impl BigInt
Sourcepub fn from_f64_truncated(value: f64) -> BigInt
pub fn from_f64_truncated(value: f64) -> BigInt
The value of an f64 truncated toward zero, which the relational comparison needs.
Only called for a finite value whose magnitude is below 1.7e38, so the exponent is
bounded and the word count stays small.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Whether the value is below zero.
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
The value as an f64, for the relational comparisons that accept a Number.
Rounding is the platform’s, which is what BigInt < Number needs: the comparison is
on the mathematical values, and an f64 cannot tell 2^60 from 2^60 + 1 anyway.
Sourcepub fn to_i64(&self) -> Option<i64>
pub fn to_i64(&self) -> Option<i64>
The value as an i64 when it fits, which BigInt.asIntN-free paths use.
Sourcepub fn from_radix(text: &str, radix: u32) -> Option<BigInt>
pub fn from_radix(text: &str, radix: u32) -> Option<BigInt>
Parse text in radix, which is what a literal and BigInt("…") both need.
Surrounding whitespace is not accepted here; the caller trims it, because the literal grammar and the string grammar differ in what they allow around the digits.
Sourcepub fn from_string(text: &str) -> Option<BigInt>
pub fn from_string(text: &str) -> Option<BigInt>
Parse a JS BigInt string: optional sign, optional 0x/0o/0b, no fraction.
Sourcepub fn div_rem(&self, other: &BigInt) -> Option<(BigInt, BigInt)>
pub fn div_rem(&self, other: &BigInt) -> Option<(BigInt, BigInt)>
Signed division, truncating toward zero, with the remainder.
None for a zero divisor, which the caller turns into a RangeError.
Sourcepub fn pow(&self, exponent: &BigInt) -> Option<BigInt>
pub fn pow(&self, exponent: &BigInt) -> Option<BigInt>
self raised to exponent, by repeated squaring.
Sourcepub fn shr(&self, bits: u64) -> BigInt
pub fn shr(&self, bits: u64) -> BigInt
self >> bits, arithmetic — the same as floor(self / 2^bits).
Sourcepub fn bitand(&self, other: &BigInt) -> BigInt
pub fn bitand(&self, other: &BigInt) -> BigInt
self & other, on the infinite two’s-complement form.
Sourcepub fn to_decimal_string(&self) -> String
pub fn to_decimal_string(&self) -> String
The decimal text, which is what toString() and the printer need.
Sourcepub fn to_radix_string(&self, radix: u32) -> String
pub fn to_radix_string(&self, radix: u32) -> String
The text in radix.