Skip to main content

Num

Enum Num 

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

an integer value (§4.5): a machine word when it fits, arbitrary precision otherwise. The reference and Python hold every integer as a big integer; here the common small values avoid a heap allocation and a deep copy on clone, which dominate at scale (F21). Always normalized — a Big never holds a value that fits in i64 — so equality and ordering are the machine-word comparison whenever both operands are small, and a Small never equals a Big.

Variants§

§

Small(i64)

fits a machine word

§

Big(Rc<BigInt>)

out of i64 range

Implementations§

Source§

impl Num

Source

pub fn zero() -> Num

zero.

Source

pub fn from_big(b: BigInt) -> Num

a big integer, demoted to Small when it fits a word.

Source

pub fn to_big(&self) -> BigInt

its value as a big integer.

Source

pub fn to_f64(&self) -> Option<f64>

its value as f64 (§4.5), None only for a non-finite big integer.

Source

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

its value as i64 when it fits.

Source

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

its value as usize when it fits and is non-negative.

Source

pub fn is_zero(&self) -> bool

whether it is zero.

Source

pub fn is_negative(&self) -> bool

whether it is negative.

Source

pub fn abs(&self) -> Num

its absolute value.

Source

pub fn bits(&self) -> u64

the number of bits in its absolute value (as BigInt::bits).

Source

pub fn from_f64(x: f64) -> Option<Num>

a float rounded toward zero to an integer, None if non-finite.

Source

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

parse a decimal (or signed) integer literal.

Trait Implementations§

Source§

impl Add for &Num

Source§

type Output = Num

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Num) -> Num

Performs the + operation. Read more
Source§

impl Add<i64> for &Num

Source§

type Output = Num

The resulting type after applying the + operator.
Source§

fn add(self, n: i64) -> Num

Performs the + operation. Read more
Source§

impl AddAssign<i64> for Num

Source§

fn add_assign(&mut self, n: i64)

Performs the += operation. Read more
Source§

impl BitAnd for &Num

Source§

type Output = Num

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &Num) -> Num

Performs the & operation. Read more
Source§

impl BitOr for &Num

Source§

type Output = Num

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &Num) -> Num

Performs the | operation. Read more
Source§

impl BitXor for &Num

Source§

type Output = Num

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &Num) -> Num

Performs the ^ operation. Read more
Source§

impl Clone for Num

Source§

fn clone(&self) -> Num

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 Num

Source§

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

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

impl Display for Num

Source§

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

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

impl Div for &Num

Source§

type Output = Num

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Num) -> Num

Performs the / operation. Read more
Source§

impl Eq for Num

Source§

impl From<BigInt> for Num

Source§

fn from(b: BigInt) -> Num

Converts to this type from the input type.
Source§

impl From<i32> for Num

Source§

fn from(n: i32) -> Num

Converts to this type from the input type.
Source§

impl From<i64> for Num

Source§

fn from(n: i64) -> Num

Converts to this type from the input type.
Source§

impl From<u32> for Num

Source§

fn from(n: u32) -> Num

Converts to this type from the input type.
Source§

impl From<u64> for Num

Source§

fn from(n: u64) -> Num

Converts to this type from the input type.
Source§

impl From<usize> for Num

Source§

fn from(n: usize) -> Num

Converts to this type from the input type.
Source§

impl Mul for &Num

Source§

type Output = Num

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Num) -> Num

Performs the * operation. Read more
Source§

impl Neg for &Num

Source§

type Output = Num

The resulting type after applying the - operator.
Source§

fn neg(self) -> Num

Performs the unary - operation. Read more
Source§

impl Neg for Num

Source§

type Output = Num

The resulting type after applying the - operator.
Source§

fn neg(self) -> Num

Performs the unary - operation. Read more
Source§

impl Ord for Num

Source§

fn cmp(&self, o: &Num) -> 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 Num

Source§

fn eq(&self, o: &Num) -> 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 Num

Source§

fn partial_cmp(&self, o: &Num) -> 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 Rem for &Num

Source§

type Output = Num

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &Num) -> Num

Performs the % operation. Read more
Source§

impl Shl<usize> for &Num

Source§

type Output = Num

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

fn shl(self, n: usize) -> Num

Performs the << operation. Read more
Source§

impl Shr<usize> for &Num

Source§

type Output = Num

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

fn shr(self, n: usize) -> Num

Performs the >> operation. Read more
Source§

impl Sub for &Num

Source§

type Output = Num

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Num) -> Num

Performs the - operation. Read more
Source§

impl Sub<i64> for &Num

Source§

type Output = Num

The resulting type after applying the - operator.
Source§

fn sub(self, n: i64) -> Num

Performs the - operation. Read more

Auto Trait Implementations§

§

impl !Send for Num

§

impl !Sync for Num

§

impl Freeze for Num

§

impl RefUnwindSafe for Num

§

impl Unpin for Num

§

impl UnsafeUnpin for Num

§

impl UnwindSafe for Num

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

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

Source§

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

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

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

Source§

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