pub struct Integer(/* private fields */);Implementations§
Source§impl Integer
impl Integer
pub const ZERO: Self
pub const ONE: Self
Sourcepub fn from_radix_digits(digits: &str, radix: u32) -> Result<Self, IntError>
pub fn from_radix_digits(digits: &str, radix: u32) -> Result<Self, IntError>
Parse unsigned binary or hexadecimal digits (no prefix or separators). Check the significant bit count before allocating a bigint. Decimal parsing remains separate so data files keep their decimal-only contract.
pub fn from_big(value: BigInt) -> Result<Self, IntError>
pub fn big(&self) -> Cow<'_, BigInt>
pub fn to_i64(&self) -> Option<i64>
pub fn to_u64(&self) -> Option<u64>
pub fn to_u128(&self) -> Option<u128>
pub fn to_f64(&self) -> Option<f64>
pub fn from_f64(x: f64) -> Option<Self>
pub fn bits(&self) -> u64
Sourcepub fn bit_and(&self, rhs: &Self) -> Result<Self, IntError>
pub fn bit_and(&self, rhs: &Self) -> Result<Self, IntError>
Signed bit operations use infinite two’s-complement sign extension.
pub fn bit_or(&self, rhs: &Self) -> Result<Self, IntError>
pub fn bit_xor(&self, rhs: &Self) -> Result<Self, IntError>
pub fn bit_not(&self) -> Result<Self, IntError>
pub fn is_negative(&self) -> bool
pub fn is_zero(&self) -> bool
pub fn is_odd(&self) -> bool
pub fn magnitude_bit(&self, i: u64) -> bool
pub fn negated(&self) -> Self
pub fn abs(&self) -> Self
pub fn add(&self, rhs: &Self) -> Result<Self, IntError>
pub fn sub(&self, rhs: &Self) -> Result<Self, IntError>
pub fn mul(&self, rhs: &Self) -> Result<Self, IntError>
pub fn div_mod(&self, rhs: &Self) -> Result<(Self, Self), IntError>
pub fn pow(&self, exponent: u32) -> Result<Self, IntError>
Sourcepub fn mod_pow(
&self,
exponent: &Self,
modulus: &Self,
) -> Result<Option<Self>, IntError>
pub fn mod_pow( &self, exponent: &Self, modulus: &Self, ) -> Result<Option<Self>, IntError>
self to the power exponent, modulo modulus, as mod gives it:
on the modulus’s side of 0. A negative exponent takes powers of the
inverse, and gives None when there’s none.
Sourcepub fn mod_inverse(&self, modulus: &Self) -> Result<Option<Self>, IntError>
pub fn mod_inverse(&self, modulus: &Self) -> Result<Option<Self>, IntError>
The inverse of self modulo modulus, as mod gives it, if they’re
coprime.
Sourcepub fn ratio(&self, denominator: &Self) -> Option<f64>
pub fn ratio(&self, denominator: &Self) -> Option<f64>
Convert the quotient jointly: individually converting huge operands would turn a finite ratio into infinity / infinity.
Sourcepub fn probability_rank(&self, p: f64) -> Result<Self, IntError>
pub fn probability_rank(&self, p: f64) -> Result<Self, IntError>
ceil(n*p) for a nonnegative n and a finite probability. The float is interpreted exactly, so rank selection works beyond float precision. The temporary product uses at most 53 extra bits above n’s size.
Sourcepub fn round_decimal(&self, places: u32) -> Result<Self, IntError>
pub fn round_decimal(&self, places: u32) -> Result<Self, IntError>
Round an integer to a power of ten, halfway away from zero. The temporary scale is bounded to at most a few bits above the value ceiling.