Skip to main content

Number

Enum Number 

Source
pub enum Number {
    Integer(BigInt),
    Rational(BigRational),
    Decimal(Decimal),
    Float64(Float64),
}
Expand description

The recursive scalar number type.

Variants§

§

Integer(BigInt)

§

Rational(BigRational)

§

Decimal(Decimal)

§

Float64(Float64)

Implementations§

Source§

impl Number

Source

pub fn integer<T: Into<BigInt>>(value: T) -> Number

Source

pub fn decimal(value: Decimal) -> Number

Source

pub fn rational(numer: BigInt, denom: BigInt) -> Result<Number, EngineError>

Source

pub fn float(value: f64) -> Result<Number, EngineError>

Source

pub fn is_zero(&self) -> bool

Source

pub fn is_negative(&self) -> bool

Source

pub fn is_float(&self) -> bool

Source

pub fn kind_name(&self) -> &'static str

Source

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

Convert to an exact rational, failing for Float64 (use Number::to_exact_rational to include floats via their exact bits).

Source

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

Convert to an exact rational, including Float64 via bit decomposition.

Source

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

Source

pub fn neg(&self) -> Number

Source

pub fn abs(&self) -> Number

Source

pub fn compare(&self, other: &Number) -> Result<Ordering, EngineError>

Exact comparison across all representations.

Source

pub fn numeric_eq(&self, other: &Number) -> Result<bool, EngineError>

Numeric equality across representations (exact semantics).

Source

pub fn add( &self, other: &Number, ctx: &NumericContext, limits: &Limits, ) -> Result<NumberResult, EngineError>

Source

pub fn sub( &self, other: &Number, ctx: &NumericContext, limits: &Limits, ) -> Result<NumberResult, EngineError>

Source

pub fn mul( &self, other: &Number, ctx: &NumericContext, limits: &Limits, ) -> Result<NumberResult, EngineError>

Source

pub fn div( &self, other: &Number, ctx: &NumericContext, limits: &Limits, ) -> Result<NumberResult, EngineError>

Source

pub fn pow( &self, exponent: &Number, ctx: &NumericContext, limits: &Limits, ) -> Result<NumberResult, EngineError>

Integer power. A non-integer exponent requires scientific mode.

Source

pub fn rem( &self, other: &Number, ctx: &NumericContext, limits: &Limits, ) -> Result<NumberResult, EngineError>

Truncated remainder: sign follows the dividend (like Rust’s %).

Source

pub fn modulo( &self, other: &Number, ctx: &NumericContext, limits: &Limits, ) -> Result<NumberResult, EngineError>

Euclidean modulo: result is non-negative for a positive modulus.

Source

pub fn round_to_scale( &self, scale: i64, mode: RoundingMode, ) -> Result<Number, EngineError>

Source§

impl Number

Source

pub fn parse_literal( source: &str, limits: &Limits, ) -> Result<Number, EngineError>

Parse a literal from expression text or a numeric shorthand string.

A literal containing . or an exponent becomes a Decimal; otherwise an Integer. Rationals and Float64 are only produced by explicit typed construction, never by guessing at text.

Trait Implementations§

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<'de> Deserialize<'de> for Number

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. 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 Eq for Number

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 Serialize for Number

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Number

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.