Skip to main content

Number

Enum Number 

Source
pub enum Number {
Show 17 variants Integer(BigInt), Rational(BigRational), Real(Real), Complex { re: Box<Number>, im: Box<Number>, }, I8(i8), I16(i16), I32(i32), I64(i64), I128(i128), U8(u8), U16(u16), U32(u32), U64(u64), U128(u128), Isize(isize), Usize(usize), BigFloat(f64),
}
Expand description

Numeric tower (spec §6.1): the exact layer Integer/Rational/Complex, the inexact layer Real, and the fixed-width collapsed layer (I8U128/Isize/Usize/BigFloat) that maps 1:1 to Rust primitives. Collapsed types exist only after explicit collapse and do not participate in implicit promotion; they are normalized to the exact/Real layer before any arithmetic (spec §6.1). The exact layer stays exact by default; a Real infects the result to inexact (spec §6.4 promotion rules).

Variants§

§

Integer(BigInt)

§

Rational(BigRational)

§

Real(Real)

§

Complex

Fields

§

I8(i8)

§

I16(i16)

§

I32(i32)

§

I64(i64)

§

I128(i128)

§

U8(u8)

§

U16(u16)

§

U32(u32)

§

U64(u64)

§

U128(u128)

§

Isize(isize)

§

Usize(usize)

§

BigFloat(f64)

Implementations§

Source§

impl Number

Source

pub fn complex(re: i64, im: i64) -> Number

Source

pub fn is_complex(&self) -> bool

Source

pub fn is_zero(&self) -> bool

Source

pub fn is_one(&self) -> bool

Source

pub fn abs(&self) -> Number

Source

pub fn sqrt(&self) -> Option<Number>

Source

pub fn pow(&self, exp: &Number) -> Option<Number>

Source

pub fn to_f64_lossy(&self) -> f64

Numeric conversion (spec §9.2 to_f64): both the exact layer and Real convert; complex returns NaN (callers must check is_complex first).

Source

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

Exact conversion to i64 (only integral values that do not overflow), otherwise None.

Source

pub fn as_i32(&self) -> Option<i32>

Exact conversion to i32 (only integral values that do not overflow), otherwise None.

Source

pub fn as_u64(&self) -> Option<u64>

Exact conversion to u64 (only non-negative integral values that do not overflow), otherwise None.

Source

pub fn as_bigint(&self) -> Option<BigInt>

Conversion to BigInt (only integral values, spec §9.2 to_bigint).

Source

pub fn as_rational(&self) -> Option<BigRational>

Conversion to BigRational (exact layer, spec §9.2 to_rational).

Source

pub fn is_integer_value(&self) -> bool

Whether this is an integral value (no fractional part, prerequisite for integer collapse in spec §9.2).

Source

pub fn as_i8(&self) -> Option<i8>

Range-checked conversion to i8 (spec §6.1 collapse layer): exact/fixed-width integral values convert if representable; Real/BigFloat convert only when integral and in range; complex never converts.

Source

pub fn as_i16(&self) -> Option<i16>

Range-checked conversion to i16 (spec §6.1 collapse layer); see as_i8.

Source

pub fn as_i128(&self) -> Option<i128>

Range-checked conversion to i128 (spec §6.1 collapse layer); see as_i8.

Source

pub fn as_u8(&self) -> Option<u8>

Range-checked conversion to u8 (spec §6.1 collapse layer); see as_i8.

Source

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

Range-checked conversion to u16 (spec §6.1 collapse layer); see as_i8.

Source

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

Range-checked conversion to u32 (spec §6.1 collapse layer); see as_i8.

Source

pub fn as_u128(&self) -> Option<u128>

Range-checked conversion to u128 (spec §6.1 collapse layer); see as_i8.

Source

pub fn as_isize(&self) -> Option<isize>

Range-checked conversion to isize (spec §6.1 collapse layer); see as_i8.

Source

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

Range-checked conversion to usize (spec §6.1 collapse layer); see as_i8.

Source

pub fn as_f32(&self) -> Option<f32>

Lossy conversion to f32 (like to_f64_lossy); complex values never convert (None).

Source

pub fn truncate(&self) -> Number

Truncate toward zero to an integer (spec §9.6 truncated_i32).

Source

pub fn round(&self) -> Number

Round to the nearest integer (spec §9.6 rounded_i32).

Source

pub fn rounded_digits(&self, digits: i64) -> Number

Round to a fixed number of decimal digits (spec §9.6 rounded_f64(x, digits)).

Source

pub fn clamped_f64(&self, min: f64, max: f64) -> Number

Clamp to [min, max] (spec §9.5 clamped_f64).

Trait Implementations§

Source§

impl Add for Number

Source§

type Output = Number

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Number) -> Number

Performs the + operation. Read more
Source§

impl Clone for Number

Source§

fn clone(&self) -> Number

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 Number

Source§

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

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

impl Display for Number

Source§

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

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

impl Div for Number

Source§

type Output = Number

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Number) -> Number

Performs the / operation. Read more
Source§

impl From<f64> for Number

Source§

fn from(v: f64) -> Number

Converts to this type from the input type.
Source§

impl From<i32> for Number

Source§

fn from(v: i32) -> Number

Converts to this type from the input type.
Source§

impl From<i64> for Number

Source§

fn from(v: i64) -> Number

Converts to this type from the input type.
Source§

impl Mul for Number

Source§

type Output = Number

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Number) -> Number

Performs the * operation. Read more
Source§

impl Neg for Number

Source§

type Output = Number

The resulting type after applying the - operator.
Source§

fn neg(self) -> Number

Performs the unary - operation. Read more
Source§

impl PartialEq for Number

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Number

Source§

impl Sub for Number

Source§

type Output = Number

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Number) -> Number

Performs the - operation. 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 = !

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.