Skip to main content

JsBigInt

Struct JsBigInt 

Source
pub struct JsBigInt(/* private fields */);
Expand description

An ECMAScript BigInt using the same short/heap split as QuickJS.

The representation is private so callers cannot construct a non-normalized heap value that should have been a short BigInt.

Implementations§

Source§

impl JsBigInt

Source

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

Test the tagged representation identity observed by QuickJS’s raw JSValue equality shortcuts. Heap values must share the same cell; numeric equality alone is deliberately insufficient.

Source

pub const fn zero() -> Self

Construct zero in the short representation.

Source

pub const fn one() -> Self

Construct one in the short representation.

Source

pub fn from_bigint(value: BigInt) -> Result<Self, BigIntError>

Construct and normalize a num_bigint::BigInt.

§Errors

Returns BigIntError::BigIntTooLarge when the signed limb representation exceeds the QuickJS allocation limit.

Source

pub fn from_integral_f64(value: f64) -> Option<Self>

Convert an exactly integral finite binary64 value to a BigInt.

This is the Number-only branch of QuickJS’s BigInt constructor. The caller retains responsibility for selecting the distinct non-integer and non-finite JavaScript errors.

Source

pub fn parse_js_string(source: &str) -> Result<Self, BigIntError>

Parse the string form accepted by the ECMAScript BigInt constructor.

Leading and trailing ECMAScript whitespace is ignored. The empty string is zero. Decimal text may have a leading + or -; unsigned 0b, 0o, and 0x prefixes are accepted. Numeric separators and a trailing n are deliberately rejected, as they are not part of StringToBigInt.

§Errors

Returns BigIntError::InvalidSyntax for malformed input and an allocation-size error for values beyond the upstream limit.

Source

pub fn parse_radix(source: &str, radix: u32) -> Result<Self, BigIntError>

Parse an optionally signed digit sequence in radix.

Unlike Self::parse_js_string, this low-level entry point does not trim whitespace or recognize a base prefix.

§Errors

Returns BigIntError::InvalidRadix, BigIntError::InvalidSyntax, or an allocation-size error.

Source

pub fn to_string_radix(&self, radix: u32) -> Result<String, BigIntError>

Format the integer with lowercase digits in radix.

§Errors

Returns BigIntError::InvalidRadix unless radix is in 2..=36.

Source

pub const fn is_short(&self) -> bool

Whether this value uses the JS_TAG_SHORT_BIG_INT-like fast path.

Source

pub const fn as_i64(&self) -> Option<i64>

Return the immediate value, or None for a heap BigInt.

Source

pub fn to_bigint(&self) -> BigInt

Return a cloned arbitrary-precision value for external integrations.

Source

pub fn to_f64(&self) -> f64

Convert this integer to the nearest IEEE-754 binary64 value.

This is the conversion used by the Number constructor’s ToNumeric path. It is deliberately separate from ordinary ToNumber, which must continue to reject BigInt primitives. num-bigint retains sticky lower bits before the final hardware conversion, yielding round-to-nearest, ties-to-even and signed infinity on overflow like pinned QuickJS.

Source

pub fn cmp_f64(&self, number: f64) -> Option<Ordering>

Compare exactly with a Number, as IsLessThan requires (None for NaN).

Source

pub fn magnitude_bits(&self) -> u64

The unsigned magnitude bit length (0 for zero).

Source

pub fn signed_limb_len(&self) -> u64

Number of normalized signed 64-bit limbs used by QuickJS.

Source

pub fn exceeds_allocation_limit(&self) -> bool

Source

pub fn is_zero(&self) -> bool

Whether this value is zero.

Source

pub fn is_negative(&self) -> bool

Whether this value is negative.

Source

pub fn add(&self, rhs: &Self) -> Result<Self, BigIntError>

Add two BigInts, promoting on short overflow and compacting the result.

§Errors

Returns BigIntError::BigIntTooLarge if the result exceeds the upstream allocation limit.

Source

pub fn sub(&self, rhs: &Self) -> Result<Self, BigIntError>

Subtract two BigInts, promoting on short overflow and compacting the result.

§Errors

Returns BigIntError::BigIntTooLarge if the result exceeds the upstream allocation limit.

Source

pub fn update_decrement(&self) -> Result<Self, BigIntError>

Apply the pinned QuickJS 2026-06-04 BigInt -- operation.

QuickJS handles ordinary short values in its VM fast path. At i64::MIN and for every heap BigInt it enters js_unary_arith_slow, where unsigned opcode-enum arithmetic turns the intended -1 limb into UINT32_MAX before js_bigint_add. This observable release quirk is deliberately confined to update-decrement; binary subtraction keeps mathematical BigInt semantics.

Source

pub fn mul(&self, rhs: &Self) -> Result<Self, BigIntError>

Multiply two BigInts, promoting on short overflow and compacting the result.

§Errors

Returns BigIntError::BigIntTooLarge if the result exceeds the upstream allocation limit.

Source

pub fn div(&self, rhs: &Self) -> Result<Self, BigIntError>

Divide with truncation toward zero, as required for ECMAScript BigInt.

§Errors

Returns BigIntError::DivisionByZero when rhs is zero.

Source

pub fn rem(&self, rhs: &Self) -> Result<Self, BigIntError>

Compute a remainder whose sign follows the dividend.

§Errors

Returns BigIntError::DivisionByZero when rhs is zero.

Source

pub fn pow(&self, exponent: &Self) -> Result<Self, BigIntError>

Raise this value to a non-negative BigInt exponent.

0, 1, and -1 retain the same constant-result shortcuts as js_bigint_pow, even when the exponent itself is too large to fit a machine integer.

§Errors

Returns BigIntError::NegativeExponent for a negative exponent, BigIntError::BigIntTooLarge when the mathematical exponent exceeds the upstream limit, and BigIntError::AllocationTooLarge when an intermediate or final allocation crosses the nominal limb guard.

Source

pub fn neg(&self) -> Result<Self, BigIntError>

Arithmetic negation, promoting i64::MIN to a heap BigInt.

§Errors

Returns BigIntError::BigIntTooLarge if the result exceeds the upstream allocation limit.

Source

pub fn bit_and(&self, rhs: &Self) -> Result<Self, BigIntError>

Infinite-width two’s-complement bitwise AND.

§Errors

Returns BigIntError::AllocationTooLarge when either operand came from QuickJS’s unguarded one-sign-limb extension.

Source

pub fn bit_or(&self, rhs: &Self) -> Result<Self, BigIntError>

Infinite-width two’s-complement bitwise OR.

§Errors

Returns BigIntError::AllocationTooLarge when either operand came from QuickJS’s unguarded one-sign-limb extension.

Source

pub fn bit_xor(&self, rhs: &Self) -> Result<Self, BigIntError>

Infinite-width two’s-complement bitwise XOR.

§Errors

Returns BigIntError::AllocationTooLarge when either operand came from QuickJS’s unguarded one-sign-limb extension.

Source

pub fn bit_not(&self) -> Result<Self, BigIntError>

Infinite-width two’s-complement bitwise NOT.

§Errors

Returns BigIntError::AllocationTooLarge when the operand came from QuickJS’s unguarded one-sign-limb extension.

Source

pub fn shl(&self, count: &Self) -> Result<Self, BigIntError>

ECMAScript BigInt left shift. A negative count shifts right.

§Errors

Returns BigIntError::ShiftTooLarge when a non-zero left-shift result would exceed the QuickJS allocation limit.

Source

pub fn shr(&self, count: &Self) -> Result<Self, BigIntError>

ECMAScript BigInt arithmetic right shift. A negative count shifts left.

§Errors

Returns BigIntError::ShiftTooLarge when a reversed (left) shift would exceed the QuickJS allocation limit.

Source

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

QuickJS 2026-06-04 behavior for BigInt.asIntN(bits, value).

§Errors

Returns BigIntError::AllocationTooLarge when truncation would allocate the 16,385th nominal limb. The pinned release still returns an already-extended input unchanged once bits reaches its storage width, so that early return remains deliberately ahead of the guard.

Source

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

QuickJS 2026-06-04 behavior for BigInt.asUintN(bits, value).

This intentionally preserves the upstream signed-limb behavior instead of silently substituting the ECMA-262 result. In this release, a short negative value is returned unchanged for bits >= 64; heap truncation at a multiple of 64 can likewise produce a negative value. These are observable compatibility requirements for the selected baseline.

§Errors

Returns BigIntError::AllocationTooLarge at the same guarded truncation boundary as Self::as_int_n.

Trait Implementations§

Source§

impl Clone for JsBigInt

Source§

fn clone(&self) -> Self

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 Debug for JsBigInt

Source§

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

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

impl Default for JsBigInt

Source§

fn default() -> Self

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

impl Display for JsBigInt

Source§

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

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

impl Eq for JsBigInt

Source§

impl From<i32> for JsBigInt

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for JsBigInt

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for JsBigInt

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for JsBigInt

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for JsBigInt

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for JsBigInt

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl FromStr for JsBigInt

Source§

type Err = BigIntError

The associated error which can be returned from parsing.
Source§

fn from_str(source: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for JsBigInt

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for JsBigInt

Source§

fn cmp(&self, other: &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§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for JsBigInt

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 PartialOrd for JsBigInt

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 StructuralPartialEq for JsBigInt

Source§

impl TryFrom<BigInt> for JsBigInt

Source§

type Error = BigIntError

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

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

Performs the conversion.

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
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> 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
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.