Skip to main content

BigInt

Struct BigInt 

Source
pub struct BigInt {
    negative: bool,
    limbs: Vec<u32>,
}
Expand description

ベース 2^32 のリムで表す符号付き任意精度整数。

Fields§

§negative: bool

true なら負。ゼロのときは必ず false(正規形)。

§limbs: Vec<u32>

絶対値のリム列(リトルエンディアン)。末尾の 0 は持たない(正規形)。

Implementations§

Source§

impl BigInt

Source

pub fn zero() -> Self

値 0。

Source

pub fn is_zero(&self) -> bool

ゼロかどうか。

Source

fn normalize(self) -> Self

末尾の 0 リムを除去し、ゼロなら符号を正に揃える(正規形化)。

Source

pub fn from_i64(v: i64) -> Self

i64 から生成。

Source

pub fn from_u64(v: u64) -> Self

u64 から生成(常に非負)。DataView.prototype.getBigUint64 用。

Source

pub fn from_f64(v: f64) -> Option<Self>

f64 から生成(整数値のみ受理。小数・非有限は None)。

Source

pub fn parse_decimal(s: &str) -> Option<Self>

十進文字列をパース(先頭に符号可、_ 区切り許容)。失敗で None。

Source

pub fn parse_str(s: &str) -> Option<Self>

文字列をパース(0x/0o/0b 接頭辞対応、それ以外は十進)。

Source

fn parse_radix(digits: &str, radix: u32) -> Option<Self>

指定基数(2〜16)の桁列をパース。

Source

fn cmp_magnitude(&self, other: &Self) -> Ordering

絶対値の大小比較。

Source

pub fn cmp(&self, other: &Self) -> Ordering

符号込みの全順序比較。

Source

fn add_magnitude(a: &[u32], b: &[u32]) -> Vec<u32>

絶対値の加算(符号は無視)。

Source

fn sub_magnitude(a: &[u32], b: &[u32]) -> Vec<u32>

絶対値の減算 a - b(a >= b を前提)。

Source

pub fn add(&self, other: &Self) -> Self

加算。

Source

pub fn sub(&self, other: &Self) -> Self

減算。

Source

pub fn neg(&self) -> Self

符号反転。

Source

pub fn abs(&self) -> Self

絶対値。

Source

pub fn mul(&self, other: &Self) -> Self

乗算(素朴な O(n*m) 筆算)。

Source

fn divmod_magnitude(a: &[u32], b: &[u32]) -> (Vec<u32>, Vec<u32>)

絶対値どうしの除算 → (商, 剰余) を絶対値で返す。 素朴なビット単位の long division(速度より明快さを優先)。

Source

fn shl_bits(&self, bits: usize) -> Self

絶対値を左へ bit ビットシフト(内部用、符号は維持)。

Source

fn shr_bits(&self, bits: usize) -> Self

絶対値を右へ bit ビットシフト(内部用、符号は維持。算術的切り捨て)。

Source

fn set_bit(&self, i: usize) -> Self

ビット i を 1 にした新しい値を返す(絶対値操作・内部用)。

Source

pub fn div(&self, other: &Self) -> Option<Self>

除算(商)。ゼロ除算は None。商は 0 方向への切り捨て(truncation)。

Source

pub fn rem(&self, other: &Self) -> Option<Self>

剰余。ゼロ除算は None。符号は被除数に従う(ECMAScript 準拠)。

Source

pub fn pow(&self, exp: &Self) -> Option<Self>

累乗(指数は非負 BigInt のみ。負指数は None)。二乗法で計算。

Source

pub fn to_decimal_string(&self) -> String

十進文字列化。

Source

pub fn to_f64(&self) -> f64

近似的に f64 へ変換(Number(bigint) 用。大きすぎる値は Infinity に近づく)。

Source

pub fn is_one(&self) -> bool

1 かどうか(絶対値が 1 で正)。

Source

fn bit_length(&self) -> usize

このビット長(絶対値を表すのに必要な最小ビット数)。ゼロは 0。

Source

fn to_twos_complement(&self, width: usize) -> Vec<u32>

指定リム数の「2 の補数表現」をリトルエンディアンの u32 列で返す。 負数は ~|x| + 1 を width リム幅で計算する。正数はゼロ拡張。

Source

fn from_twos_complement(limbs: Vec<u32>) -> Self

width リム幅の 2 の補数表現(リトルエンディアン)から BigInt を復元する。 最上位ビットが 1 なら負数とみなす。

Source

fn bitop_width(&self, other: &Self) -> usize

2 つの値のビット演算に必要なリム幅(両者の絶対値ビット長 + 符号ビット余裕)。

Source

pub fn bitand(&self, other: &Self) -> Self

ビット AND(2 の補数の無限長セマンティクス)。

Source

pub fn bitor(&self, other: &Self) -> Self

ビット OR。

Source

pub fn bitxor(&self, other: &Self) -> Self

ビット XOR。

Source

pub fn bitnot(&self) -> Self

ビット NOT(~x = -(x+1)、2 の補数の恒等式)。

Source

pub fn shl(&self, count: i64) -> Self

左シフト(count は非負 i64。符号は保存、絶対値を count ビット左へ)。

Source

pub fn shr(&self, count: i64) -> Self

右シフト(算術シフト = 床方向。負数では -infinity 方向へ丸める ECMAScript 準拠)。

Source

pub fn as_uint_n(&self, bits: u64) -> Self

BigInt.asUintN(bits, x): 下位 bits ビットを符号なし整数として解釈。

Source

pub fn as_int_n(&self, bits: u64) -> Self

BigInt.asIntN(bits, x): 下位 bits ビットを符号付き 2 の補数として解釈。

Source

pub fn to_u64_truncated(&self) -> u64

下位64ビットを2の補数のビットパターンとして u64 へ切り詰める。 DataView.prototype.setBigInt64/setBigUint64 がバイト列へ書き戻す際に使う。

Trait Implementations§

Source§

impl Clone for BigInt

Source§

fn clone(&self) -> BigInt

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Eq for BigInt

Source§

impl PartialEq for BigInt

Source§

fn eq(&self, other: &BigInt) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for BigInt

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.