docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

core::num::bigint

本页内容

API 参考只有英文版,由标准库源代码中的英文文档注释生成。

int, the arbitrary-precision integer. #[keyword("int")] routes the type name here; an unsuffixed literal in an int slot is built by Int::from_i64 / Int::from_literal.

Structs

IntSource

pub struct Int

An arbitrary-precision integer. Write it int.

  • pub const fn from_i64(n: i64) -> Int§

    Source

    The value n.

  • pub const fn from_i32(n: i32) -> Int§

    Source

    The value n.

  • pub const fn from_u64(n: u64) -> Int§

    Source

    The value n.

  • pub fn parse_radix(s: str, radix: u32) throws (ParseError) -> Int§

    Source

    s in base radix: an optional sign, then digits of either case. The grammar is the runtime's, the same the primitives' FromStr reads. Panics when radix is outside 2..=36.

  • pub fn to_str_radix(self, radix: u32) -> str§

    Source

    The digits in base radix (2..=36, lowercase), - first when negative.

  • pub const fn to_i32(self) -> i32 | none§

    Source

    The value as an i32; none when it does not fit.

  • pub const fn to_i64(self) -> i64 | none§

    Source

    The value as an i64; none when it does not fit.

  • pub const fn to_u64(self) -> u64 | none§

    Source

    The value as a u64; none when negative or too large.

  • pub fn to_f64(self) -> f64§

    Source

    The nearest f64 (ties to even; +/-inf past f64::MAX).

  • pub const fn is_zero(self) -> bool§

    Source

    true for 0.

  • pub const fn is_negative(self) -> bool§

    Source

    true below 0.

  • pub const fn is_positive(self) -> bool§

    Source

    true above 0.

  • pub const fn signum(self) -> Int§

    Source

    -1, 0 or 1.

  • pub const fn abs(self) -> Int§

    Source

    The magnitude.

  • pub const fn bit_length(self) -> u64§

    Source

    Bits of |self| without leading zeros (0 for zero; Python's bit_length).

  • pub const fn count_ones(self) -> u64§

    Source

    One bits of |self| (Python's bit_count): a negative number has infinitely many in two's complement.

  • pub const fn trailing_zeros(self) -> u64 | none§

    Source

    Zero bits below the lowest one bit, the same for self and -self; none for zero, which has no one bit.

  • pub const fn bit(self, n: u64) -> bool§

    Source

    Bit n of self in two's complement, sign-extended forever: a negative number has every high bit set.

  • pub const fn set_bit(ref self, n: u64, value: bool)§

    Source

    Sets bit n (as bit reads it) to value.

  • pub const fn is_power_of_two(self) -> bool§

    Source

    self == 2^k for some k; false for zero and negatives.

  • pub const fn next_power_of_two(self) -> Int§

    Source

    The smallest power of two >= self; 1 for self <= 1.

  • pub const fn ilog2(self) -> u64§

    Source

    floor(log2(self)); panics unless self > 0.

  • pub const fn checked_ilog2(self) -> u64 | none§

    Source

    floor(log2(self)); none unless self > 0.

  • pub fn to_le_bytes(self) -> List<u8>§

    Source

    The shortest two's complement, least significant first: the top bit is the sign (-1 is [255], 128 is [128, 0]); zero is [0]. Fixed-width integers' to_le_bytes agree in their width.

  • pub fn to_be_bytes(self) -> List<u8>§

    Source

    As to_le_bytes, most significant first.

  • pub fn to_le_bytes_unsigned(self) -> List<u8>§

    Source

    The magnitude, least significant first, with no sign bit (255 is [255]); zero is [0]. Panics on a negative number.

  • pub fn to_be_bytes_unsigned(self) -> List<u8>§

    Source

    As to_le_bytes_unsigned, most significant first.

  • pub fn byte_len(self) -> usize§

    Source

    The length of to_le_bytes().

  • pub fn byte_len_unsigned(self) -> usize§

    Source

    The length of to_le_bytes_unsigned(); panics on a negative number.

  • pub fn from_le_bytes<B: AsBytes>(bytes: B) -> Int§

    Source

    The int of bytes in two's complement, least significant first (a set top bit is negative). No bytes is zero.

  • pub fn from_be_bytes<B: AsBytes>(bytes: B) -> Int§

    Source

    As from_le_bytes, most significant first.

  • pub fn from_le_bytes_unsigned<B: AsBytes>(bytes: B) -> Int§

    Source

    The int of the magnitude bytes, least significant first; never negative. No bytes is zero.

  • pub fn from_be_bytes_unsigned<B: AsBytes>(bytes: B) -> Int§

    Source

    As from_le_bytes_unsigned, most significant first.

  • pub fn write_le_bytes(self, out: SliceMut<u8>)§

    Source

    self in two's complement in exactly out.len() bytes, least significant first, sign-extended. Panics if it needs more bytes (byte_len() > out.len()).

  • pub fn write_be_bytes(self, out: SliceMut<u8>)§

    Source

    As write_le_bytes, most significant first.

  • pub fn write_le_bytes_unsigned(self, out: SliceMut<u8>)§

    Source

    The magnitude in exactly out.len() bytes, least significant first, zero-extended. Panics on a negative number or if it needs more bytes (byte_len_unsigned() > out.len()).

  • pub fn write_be_bytes_unsigned(self, out: SliceMut<u8>)§

    Source

    As write_le_bytes_unsigned, most significant first.

  • pub fn pow(self, exp: u32) -> Int§

    Source

    self^exp (square and multiply).

  • pub fn modpow(self, exp: Int, m: Int) -> Int§

    Source

    self^exp %% m: in 0..m for m > 0, m + 1..=0 for m < 0 (the sign of m, as %%). Panics if m is zero or exp negative.

  • pub fn gcd(self, other: Int) -> Int§

    Source

    The 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) -> Int§

    Source

    The least common multiple, never negative (0 if either is).

  • pub fn div_euclid(self, rhs: Int) -> Int§

    Source

    The quotient rounded so that rem_euclid is never negative; panics on zero.

  • pub fn rem_euclid(self, rhs: Int) -> Int§

    Source

    The remainder in 0..rhs.abs(); panics on zero.

  • pub fn isqrt(self) -> Int§

    Source

    floor(sqrt(self)); panics on a negative number.

  • pub fn checked_isqrt(self) -> Int | none§

    Source

    floor(sqrt(self)), none for a negative number. Newton steps doubling the precision (the recursion of Python's math.isqrt): each refines the root of the top 2d bits from that of the top 2e bits, e = d / 2.

  • pub fn div_rem(self, rhs: Int) -> (Int, Int)§

    Source

    (self / rhs, self % rhs) in one division (truncating, like / and %); panics on zero.