pub struct BigInt<A: IVm>(/* private fields */);Expand description
use nanvm_lib::{vm::{BigInt, IVm}, naive::Naive};
fn bigint_test<A: IVm>() {
let a: BigInt<A> = 12345678901234567890u64.into();
let b: BigInt<A> = (-1234567890123456789i64).into();
}
bigint_test::<Naive>();Implementations§
Source§impl<A: IVm> BigInt<A>
impl<A: IVm> BigInt<A>
Sourcepub fn pow(self, rhs: Self) -> Result<Self, Any<A>>
pub fn pow(self, rhs: Self) -> Result<Self, Any<A>>
**. Not a core::ops trait — Rust has no operator for
exponentiation, so this is a plain method, the same as Any::pow
one level up.
Exponentiation by squaring, walking the exponent’s own bits rather
than converting it to a Rust integer, so an exponent wider than
u64 still works. A negative exponent throws instead of coercing to
a fraction, unlike Number ** Number, since BigInt has none. A
power longer than MAX_WORDS words throws the RangeError that *
throws for the multiplication that crosses it.
Source§impl<A: IVm> BigInt<A>
impl<A: IVm> BigInt<A>
Sourcepub fn to_number(&self) -> Number
pub fn to_number(&self) -> Number
Number(bigint): the nearest Number, a tie going to the even
significand, and Infinity or -Infinity past the range.
https://tc39.es/ecma262/#sec-numberbigint
The top two words are the significand Number::compose rounds, and
any word below them set is its sticky bit: with the top word not
zero, the two hold at least 65 significant bits, more than the 54 the
sticky bit needs.
Source§impl<A: IVm> BigInt<A>
impl<A: IVm> BigInt<A>
Sourcepub fn normalize_new(sign: Sign, items: impl IntoIterator<Item = u64>) -> Self
pub fn normalize_new(sign: Sign, items: impl IntoIterator<Item = u64>) -> Self
Note: this function accepts an iterator in least-significant-word-first order, i.e. the first item is the least significant word!
Sourcepub fn div_mod(self, rhs: Self) -> Result<(Self, Self), Any<A>>
pub fn div_mod(self, rhs: Self) -> Result<(Self, Self), Any<A>>
Truncating division: (self / rhs, self % rhs).
The single owner of the protocol Div and Rem project from: the
zero-divisor guard, the magnitude division, and both sign rules. The
quotient truncates toward zero, so it is negative iff exactly one
operand is; the remainder’s sign follows the dividend. Both match
Rust’s own integer / and %. Only the zero divisor is special: JS
throws instead of the NaN a Number operation would give.
Trait Implementations§
Source§impl<A: IVm> Add for BigInt<A>
+, or the RangeError of a sum longer than MAX_WORDS words, as *
and << throw for a result that long.
impl<A: IVm> Add for BigInt<A>
+, or the RangeError of a sum longer than MAX_WORDS words, as *
and << throw for a result that long.
impl<A: IVm> Eq for BigInt<A>
Source§impl<A: IVm> Mul for BigInt<A>
*, or the RangeError of a product longer than MAX_WORDS words, as
<< throws for a shift that long.
impl<A: IVm> Mul for BigInt<A>
*, or the RangeError of a product longer than MAX_WORDS words, as
<< throws for a shift that long.
Source§impl<A: IVm> Ord for BigInt<A>
The single owner of how two BigInts relate: PartialEq (in
partial_eq.rs) and PartialOrd both delegate here.
impl<A: IVm> Ord for BigInt<A>
The single owner of how two BigInts relate: PartialEq (in
partial_eq.rs) and PartialOrd both delegate here.
Invariant: both operands are normalized — no leading (most-significant)
zero words, and zero is always Sign::Positive with no words (no negative
zero). That is what makes the sign order sound (a negative value is always
below a positive one) and what abs_cmp_vec asserts; a non-normalized
operand panics.
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<A: IVm> PartialEq for BigInt<A>
Equality is defined by Ord (in cmp.rs), the single owner of how two
BigInts relate, so a == b holds exactly when a.cmp(&b) == Equal by
construction rather than by two code paths happening to agree.
impl<A: IVm> PartialEq for BigInt<A>
Equality is defined by Ord (in cmp.rs), the single owner of how two
BigInts relate, so a == b holds exactly when a.cmp(&b) == Equal by
construction rather than by two code paths happening to agree.
Invariant: both operands are normalized — no leading (most-significant)
zero words, and zero is always Sign::Positive with no words (no negative
zero). Ord relies on it and panics on a non-normalized operand, which
only unchecked_new can build.
Source§impl<A: IVm> PartialOrd for BigInt<A>
impl<A: IVm> PartialOrd for BigInt<A>
Source§impl<A: IVm> Shr for BigInt<A>
impl<A: IVm> Shr for BigInt<A>
Conceptually a shift over self’s infinite-precision two’s-complement
bit string — equivalently, floor division by 2^rhs — not a shift of
self’s magnitude with the sign carried along unchanged: those agree
for a non-negative self (floor division truncates toward zero there
anyway) but not for a negative one, where flooring rounds away from
zero whenever a nonzero bit is shifted out. -1n >> 1n is -1n (all
bits are 1, so shifting right forever still reads all 1s), not 0n
the way carrying the sign over a plain magnitude shift would give.