pub enum NumberValue {
Integer(i64),
Float(f64),
}Expand description
Specialised numeric representation. Integers stay in i64 unless they overflow during arithmetic, in which case the result falls back to f64.
Variants§
Implementations§
Source§impl NumberValue
impl NumberValue
pub fn from_i64(value: i64) -> Self
Sourcepub fn from_f64(value: f64) -> Self
pub fn from_f64(value: f64) -> Self
Construct from an f64. Whole-valued floats within i64 range collapse
to Integer so subsequent arithmetic uses the integer fast path.
pub fn is_integer(&self) -> bool
pub fn as_i64(&self) -> Option<i64>
pub fn as_f64(&self) -> f64
pub fn is_zero(&self) -> bool
pub fn is_nan(&self) -> bool
Sourcepub fn add(&self, other: &NumberValue) -> NumberValue
pub fn add(&self, other: &NumberValue) -> NumberValue
Add. Integer-integer uses checked_add; on overflow falls back to f64.
pub fn sub(&self, other: &NumberValue) -> NumberValue
pub fn mul(&self, other: &NumberValue) -> NumberValue
Sourcepub fn div(&self, other: &NumberValue) -> Option<NumberValue>
pub fn div(&self, other: &NumberValue) -> Option<NumberValue>
Divide. Returns None for division by zero — callers handle.
Sourcepub fn rem(&self, other: &NumberValue) -> Option<NumberValue>
pub fn rem(&self, other: &NumberValue) -> Option<NumberValue>
Modulo. Returns None for division by zero — caller handles.
pub fn neg(&self) -> NumberValue
pub fn abs(&self) -> NumberValue
Trait Implementations§
Source§impl Clone for NumberValue
impl Clone for NumberValue
Source§fn clone(&self) -> NumberValue
fn clone(&self) -> NumberValue
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NumberValue
impl Debug for NumberValue
Source§impl Display for NumberValue
impl Display for NumberValue
Source§impl PartialEq for NumberValue
impl PartialEq for NumberValue
Source§impl PartialOrd for NumberValue
impl PartialOrd for NumberValue
impl Copy for NumberValue
Auto Trait Implementations§
impl Freeze for NumberValue
impl RefUnwindSafe for NumberValue
impl Send for NumberValue
impl Sync for NumberValue
impl Unpin for NumberValue
impl UnsafeUnpin for NumberValue
impl UnwindSafe for NumberValue
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