pub enum Num {
Int(isize),
BigInt(Rc<BigInt>),
Float(f64),
Dec(Rc<String>),
}Expand description
Integer / decimal number.
The speciality of this type is that numbers are distinguished into integers and 64-bit floating-point numbers. This allows using integers to index arrays, while using floating-point numbers to do general math.
Operations on numbers follow a few principles:
- The sum, difference, product, and remainder of two integers is integer.
- Any other operation between two numbers yields a float.
Variants§
Int(isize)
Machine-size integer
BigInt(Rc<BigInt>)
Arbitrarily large integer
Float(f64)
Floating-point number
Dec(Rc<String>)
Decimal number
Implementations§
Source§impl Num
impl Num
Sourcepub fn from_integral<T: Copy + TryInto<isize> + Into<BigInt>>(x: T) -> Self
pub fn from_integral<T: Copy + TryInto<isize> + Into<BigInt>>(x: T) -> Self
Convert from an integral type to a machine-sized or big integer.
Sourcepub fn from_str_radix(i: &str, radix: u32) -> Option<Self>
pub fn from_str_radix(i: &str, radix: u32) -> Option<Self>
Try to parse an integer from a string with given radix.
Sourcepub fn from_dec_str(n: &str) -> Self
pub fn from_dec_str(n: &str) -> Self
Try to parse a decimal string to a Self::Float, else return NaN.
Trait Implementations§
Source§impl Ord for Num
impl Ord for Num
Source§impl PartialOrd for Num
impl PartialOrd for Num
impl Eq for Num
Auto Trait Implementations§
impl Freeze for Num
impl RefUnwindSafe for Num
impl !Send for Num
impl !Sync for Num
impl Unpin for Num
impl UnsafeUnpin for Num
impl UnwindSafe for Num
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.