Skip to main content

BigInt

Struct BigInt 

Source
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>

Source

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>

Source

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>

Source

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!

Source

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.

Source§

type Output = Result<BigInt<A>, Any<A>>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<A: IVm> BitAnd for BigInt<A>

Source§

type Output = BigInt<A>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<A: IVm> BitOr for BigInt<A>

Source§

type Output = BigInt<A>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<A: IVm> BitXor for BigInt<A>

Source§

type Output = BigInt<A>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<A: Clone + IVm> Clone for BigInt<A>

Source§

fn clone(&self) -> BigInt<A>

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<A: IVm> Debug for BigInt<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: IVm> Default for BigInt<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: IVm> Display for BigInt<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: IVm> Div for BigInt<A>

Source§

fn div(self, rhs: Self) -> Self::Output

The quotient of BigInt::div_mod.

Source§

type Output = Result<BigInt<A>, Any<A>>

The resulting type after applying the / operator.
Source§

impl<A: IVm> Eq for BigInt<A>

Source§

impl<A: IVm> From<BigInt<A>> for Unpacked<A>

Source§

fn from(value: BigInt<A>) -> Self

Converts to this type from the input type.
Source§

impl<A: IVm> From<i64> for BigInt<A>

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl<A: IVm> From<u64> for BigInt<A>

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl<A: IVm> Index<u32> for BigInt<A>

Source§

type Output = u64

The returned type after indexing.
Source§

fn index(&self, index: u32) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
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.

Source§

type Output = Result<BigInt<A>, Any<A>>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<A: IVm> Neg for BigInt<A>

Source§

type Output = BigInt<A>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
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.

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.

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
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.

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§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<A: IVm> PartialOrd for BigInt<A>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<A: IVm> Rem for BigInt<A>

Source§

fn rem(self, rhs: Self) -> Self::Output

The remainder of BigInt::div_mod.

Source§

type Output = Result<BigInt<A>, Any<A>>

The resulting type after applying the % operator.
Source§

impl<A: IVm> Shl for BigInt<A>

Source§

type Output = Result<BigInt<A>, Any<A>>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: Self) -> Self::Output

Performs the << operation. Read more
Source§

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.

Source§

type Output = Result<BigInt<A>, Any<A>>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: Self) -> Self::Output

Performs the >> operation. Read more
Source§

impl<A: IVm> Sub for BigInt<A>

-, or the RangeError of a difference longer than MAX_WORDS words, as +, * and << throw for a result that long.

Source§

type Output = Result<BigInt<A>, Any<A>>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<A: IVm> TryFrom<Any<A>> for BigInt<A>

Source§

type Error = Any<A>

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

fn try_from(value: Any<A>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<A> Freeze for BigInt<A>
where <A as IVm>::InternalBigInt: Freeze,

§

impl<A> RefUnwindSafe for BigInt<A>

§

impl<A> Send for BigInt<A>
where <A as IVm>::InternalBigInt: Send,

§

impl<A> Sync for BigInt<A>
where <A as IVm>::InternalBigInt: Sync,

§

impl<A> Unpin for BigInt<A>
where <A as IVm>::InternalBigInt: Unpin,

§

impl<A> UnsafeUnpin for BigInt<A>

§

impl<A> UnwindSafe for BigInt<A>
where <A as IVm>::InternalBigInt: UnwindSafe,

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
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<W> SizedIndex<u32> for W
where W: ContainerWrapper,

Source§

fn length(&self) -> u32

Source§

fn is_empty(&self) -> bool

Source§

fn last(&self) -> Option<&Self::Output>

Source§

fn index_iter(self) -> IndexIter<I, Self> ⓘ
where Self: Sized,

Source§

impl<T> ToAny for T

Source§

fn to_any<A: IVm>(self) -> Any<A>
where Self: Into<Unpacked<A>>,

Source§

impl<T> ToArray for T

Source§

fn to_array<A: IVm>(self) -> Array<A>
where Self: Sized + IntoIterator<Item = Any<A>>,

Source§

impl<T> ToObject for T

Source§

fn to_object<A: IVm>(self) -> Object<A>
where Self: Sized + IntoIterator<Item = Property<A>>,

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> ToString for T

Source§

fn try_to_string<A: IVm>(self) -> Result<String<A>, Any<A>>
where Self: Sized + IntoIterator<Item = Result<u16, Any<A>>>,

Source§

fn to_string<A: IVm>(self) -> String<A>
where Self: Sized + IntoIterator<Item = u16>,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.