pub enum Number {
}Expand description
Numeric tower (spec §6.1): the exact layer Integer/Rational/Complex, the inexact layer Real,
and the fixed-width collapsed layer (I8…U128/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
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
impl Number
pub fn complex(re: i64, im: i64) -> Number
pub fn is_complex(&self) -> bool
pub fn is_zero(&self) -> bool
pub fn is_one(&self) -> bool
pub fn abs(&self) -> Number
pub fn sqrt(&self) -> Option<Number>
pub fn pow(&self, exp: &Number) -> Option<Number>
Sourcepub fn to_f64_lossy(&self) -> f64
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).
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Exact conversion to i64 (only integral values that do not overflow), otherwise None.
Sourcepub fn as_i32(&self) -> Option<i32>
pub fn as_i32(&self) -> Option<i32>
Exact conversion to i32 (only integral values that do not overflow), otherwise None.
Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Exact conversion to u64 (only non-negative integral values that do not overflow), otherwise None.
Sourcepub fn as_bigint(&self) -> Option<BigInt>
pub fn as_bigint(&self) -> Option<BigInt>
Conversion to BigInt (only integral values, spec §9.2 to_bigint).
Sourcepub fn as_rational(&self) -> Option<BigRational>
pub fn as_rational(&self) -> Option<BigRational>
Conversion to BigRational (exact layer, spec §9.2 to_rational).
Sourcepub fn is_integer_value(&self) -> bool
pub fn is_integer_value(&self) -> bool
Whether this is an integral value (no fractional part, prerequisite for integer collapse in spec §9.2).
Sourcepub fn as_i8(&self) -> Option<i8>
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.
Sourcepub fn as_i16(&self) -> Option<i16>
pub fn as_i16(&self) -> Option<i16>
Range-checked conversion to i16 (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_i128(&self) -> Option<i128>
pub fn as_i128(&self) -> Option<i128>
Range-checked conversion to i128 (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_u8(&self) -> Option<u8>
pub fn as_u8(&self) -> Option<u8>
Range-checked conversion to u8 (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_u16(&self) -> Option<u16>
pub fn as_u16(&self) -> Option<u16>
Range-checked conversion to u16 (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Range-checked conversion to u32 (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_u128(&self) -> Option<u128>
pub fn as_u128(&self) -> Option<u128>
Range-checked conversion to u128 (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_isize(&self) -> Option<isize>
pub fn as_isize(&self) -> Option<isize>
Range-checked conversion to isize (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_usize(&self) -> Option<usize>
pub fn as_usize(&self) -> Option<usize>
Range-checked conversion to usize (spec §6.1 collapse layer); see as_i8.
Sourcepub fn as_f32(&self) -> Option<f32>
pub fn as_f32(&self) -> Option<f32>
Lossy conversion to f32 (like to_f64_lossy); complex values never convert (None).
Sourcepub fn rounded_digits(&self, digits: i64) -> Number
pub fn rounded_digits(&self, digits: i64) -> Number
Round to a fixed number of decimal digits (spec §9.6 rounded_f64(x, digits)).
Sourcepub fn clamped_f64(&self, min: f64, max: f64) -> Number
pub fn clamped_f64(&self, min: f64, max: f64) -> Number
Clamp to [min, max] (spec §9.5 clamped_f64).