Skip to main content

AverInt

Enum AverInt 

Source
pub enum AverInt {
    Small(i64),
    Big(Box<BigInt>),
}
Expand description

Arbitrary-precision integer (mathematical ℤ) with a small-int fast path.

Invariant: Big never holds a value representable as i64 (see module docs). Always construct/renormalize through this type’s API.

Variants§

§

Small(i64)

A value that fits i64 — the common, allocation-free case.

§

Big(Box<BigInt>)

A value outside the i64 range. Boxed to keep the enum small (a bare BigInt is three machine words; boxing keeps AverInt at two).

Implementations§

Source§

impl AverInt

Source

pub const fn from_i64(n: i64) -> Self

The mathematical integer n, stored inline.

Source

pub const fn zero() -> Self

Zero.

Source

pub fn from_bigint(b: BigInt) -> Self

Renormalize a BigInt to canonical form: demote to Small when it fits i64, otherwise box it as Big. Every path that produces or reconstructs a BigInt must funnel through here so the canonical invariant (a value fitting i64 is always Small) holds — this is the sole sanctioned way to build a Big, which is why Big’s payload is private.

Source

pub fn is_zero(&self) -> bool

true for the additive identity.

Source

pub fn add(&self, rhs: &AverInt) -> AverInt

self + rhs over ℤ (never wraps).

Source

pub fn sub(&self, rhs: &AverInt) -> AverInt

self - rhs over ℤ (never wraps).

Source

pub fn mul(&self, rhs: &AverInt) -> AverInt

self * rhs over ℤ (never wraps).

Source

pub fn neg(&self) -> AverInt

-self over ℤ (never wraps; -i64::MIN promotes to Big).

Source

pub fn div_euclid(&self, rhs: &AverInt) -> Option<AverInt>

Euclidean quotient, matching i64::div_euclid and the Lean/Dafny Int.ediv model the proofs cite: the unique q with a remainder in [0, |rhs|). Returns None when rhs == 0. Over ℤ there is no i64::MIN / -1 overflow edge — it is just i64::MAX + 1, returned as a Big.

Source

pub fn rem_euclid(&self, rhs: &AverInt) -> Option<AverInt>

Euclidean remainder self - rhs * div_euclid(self, rhs), matching i64::rem_euclid and the Lean/Dafny Int.emod model. Returns None when rhs == 0. The result is always non-negative and in [0, |rhs|), independent of the sign of either operand.

Source

pub fn div_trunc(&self, rhs: &AverInt) -> Option<AverInt>

Truncating quotient (rounds toward zero), the semantics of the raw / operator. Returns None when rhs == 0. Distinct from div_euclid for negative operands; provided for the low-level arithmetic opcodes (Int.div uses the Euclidean form).

Source

pub fn rem_trunc(&self, rhs: &AverInt) -> Option<AverInt>

Truncating remainder (sign follows the dividend), the semantics of the raw % operator. Returns None when rhs == 0.

Source

pub fn abs(&self) -> AverInt

|self| over ℤ (never wraps; |i64::MIN| promotes to Big).

Source

pub fn min_ref(&self, other: &AverInt) -> AverInt

The smaller of self and other (borrowing form, to avoid the by-value Ord::min/max and keep the small-int clone cheap).

Source

pub fn max_ref(&self, other: &AverInt) -> AverInt

The larger of self and other.

Source

pub fn to_i64(&self) -> Option<i64>

self as i64 if it fits, else None.

Source

pub fn to_usize(&self) -> Option<usize>

self as usize if it fits (non-negative and in range), else None.

Source

pub fn to_u16(&self) -> Option<u16>

self as u16 if it fits, else None.

Source

pub fn to_u32(&self) -> Option<u32>

self as u32 if it fits, else None.

Source

pub fn to_f64(&self) -> f64

self as f64, lossily. Huge magnitudes saturate to ±∞ (never NaN), matching the Lean prelude’s Float.ofInt/IEEE coercion. This is the only intentionally-lossy conversion.

Source

pub fn from_f64_trunc(f: f64) -> AverInt

Truncate a finite f64 toward zero into ℤ. The exact mirror of the VM’s float_to_aver_int (src/types/int.rs): non-finite (NaN/±∞) maps to 0; an in-i64-range truncated value stays Small; an out-of-range finite magnitude is represented EXACTLY as a Big via BigInt::from_f64.

This is the constructor Int.fromFloat and Float.floor/ceil/round must funnel through — a bare f as i64 cast SATURATES huge finite floats to i64::MAX/MIN (a silent wrong value), which this avoids.

Trait Implementations§

Source§

impl AverDisplay for AverInt

Source§

impl Clone for AverInt

Source§

fn clone(&self) -> AverInt

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 AverInt

Source§

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

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

impl Display for AverInt

Source§

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

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

impl Eq for AverInt

Source§

impl From<i64> for AverInt

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl FromStr for AverInt

Source§

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

Parse a decimal integer of arbitrary length. Rejects empty/garbage input (and anything BigInt rejects) with Err(()).

Source§

type Err = ()

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

impl Hash for AverInt

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 AverInt

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§

impl PartialEq for AverInt

Source§

fn eq(&self, other: &Self) -> 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 PartialOrd for AverInt

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

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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V