pub enum Number {
}Expand description
Represents a generic number that maintains an internal Rust representation of the actual number
Variants§
F32(f32)
F64(f64)
I128(i128)
I16(i16)
I32(i32)
I64(i64)
I8(i8)
Isize(isize)
U128(u128)
U16(u16)
U32(u32)
U64(u64)
U8(u8)
Usize(usize)
Implementations§
Source§impl Number
impl Number
Sourcepub fn sign(&self) -> NumberSign
pub fn sign(&self) -> NumberSign
Returns an indicator of the sign (negative, zero, positive) of this number
use entity::{Number, NumberSign};
assert_eq!(Number::from(0).sign(), NumberSign::Zero);
assert_eq!(Number::from(99).sign(), NumberSign::Positive);
assert_eq!(Number::from(-99).sign(), NumberSign::Negative);Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns true if number is zero (not negative or positive)
use entity::Number;
assert!(Number::from(0).is_zero());
assert!(!Number::from(1).is_zero());
assert!(!Number::from(-1).is_zero());Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if number is positive (not zero or negative)
§Examples
use entity::Number;
assert!(Number::from(1).is_positive());
assert!(!Number::from(0).is_positive());
assert!(!Number::from(-1).is_positive());Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if number is negative (not zero or positive)
§Examples
use entity::Number;
assert!(Number::from(-1).is_negative());
assert!(!Number::from(0).is_negative());
assert!(!Number::from(1).is_negative());Sourcepub fn is_signed(&self) -> bool
pub fn is_signed(&self) -> bool
Returns true if number is a signed integer
§Examples
use entity::Number;
assert!(Number::from(3isize).is_signed());
assert!(!Number::from(3usize).is_signed());Sourcepub fn is_unsigned(&self) -> bool
pub fn is_unsigned(&self) -> bool
Returns true if number is an unsigned integer
§Examples
use entity::Number;
assert!(Number::from(3usize).is_unsigned());
assert!(!Number::from(3isize).is_unsigned());Sourcepub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
Returns true if number is a float
§Examples
use entity::Number;
assert!(Number::from(3f32).is_float());
assert!(!Number::from(3usize).is_float());Sourcepub fn has_nonzero_fraction(&self) -> bool
pub fn has_nonzero_fraction(&self) -> bool
Returns true if number is a float with a non-zero fractional part
§Examples
use entity::Number;
assert!(Number::from(3.1).has_nonzero_fraction());
assert!(!Number::from(3.0).has_nonzero_fraction());Sourcepub fn is_normal(&self) -> bool
pub fn is_normal(&self) -> bool
Returns true if number is neither zero, infinite, subnormal, or NaN
§Examples
use entity::Number;
assert!(Number::from(1).is_normal());
assert!(Number::from(0.1).is_normal());
assert!(!Number::from(0).is_normal());
assert!(!Number::from(f64::NAN).is_normal());
assert!(!Number::from(f64::INFINITY).is_normal());
assert!(!Number::from(f64::NEG_INFINITY).is_normal());
assert!(!Number::from(1.0e-308_f64).is_normal());Sourcepub fn to_absolute(&self) -> Self
pub fn to_absolute(&self) -> Self
Returns a conversion of the underlying number to an absolute version of itself
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
Naive casting of number’s inner representation to f64by performing x as f64
Sourcepub fn to_f32(&self) -> f32
pub fn to_f32(&self) -> f32
Naive casting of number’s inner representation to f32by performing x as f32
Sourcepub fn to_isize(&self) -> isize
pub fn to_isize(&self) -> isize
Naive casting of number’s inner representation to isizeby performing x as isize
Sourcepub fn to_i128(&self) -> i128
pub fn to_i128(&self) -> i128
Naive casting of number’s inner representation to i128by performing x as i128
Sourcepub fn to_i64(&self) -> i64
pub fn to_i64(&self) -> i64
Naive casting of number’s inner representation to i64by performing x as i64
Sourcepub fn to_i32(&self) -> i32
pub fn to_i32(&self) -> i32
Naive casting of number’s inner representation to i32by performing x as i32
Sourcepub fn to_i16(&self) -> i16
pub fn to_i16(&self) -> i16
Naive casting of number’s inner representation to i16by performing x as i16
Sourcepub fn to_i8(&self) -> i8
pub fn to_i8(&self) -> i8
Naive casting of number’s inner representation to i8by performing x as i8
Sourcepub fn to_usize(&self) -> usize
pub fn to_usize(&self) -> usize
Naive casting of number’s inner representation to usizeby performing x as usize
Sourcepub fn to_u128(&self) -> u128
pub fn to_u128(&self) -> u128
Naive casting of number’s inner representation to u128by performing x as u128
Sourcepub fn to_u64(&self) -> u64
pub fn to_u64(&self) -> u64
Naive casting of number’s inner representation to u64by performing x as u64
Sourcepub fn to_u32(&self) -> u32
pub fn to_u32(&self) -> u32
Naive casting of number’s inner representation to u32by performing x as u32
Sourcepub fn to_u16(&self) -> u16
pub fn to_u16(&self) -> u16
Naive casting of number’s inner representation to u16by performing x as u16
Sourcepub fn to_u8(&self) -> u8
pub fn to_u8(&self) -> u8
Naive casting of number’s inner representation to u8by performing x as u8
Sourcepub fn to_type(&self) -> NumberType
pub fn to_type(&self) -> NumberType
Converts into type of number
Trait Implementations§
Source§impl<'_enum> From<&'_enum Number> for NumberType
impl<'_enum> From<&'_enum Number> for NumberType
Source§fn from(val: &'_enum Number) -> NumberType
fn from(val: &'_enum Number) -> NumberType
Source§impl From<Number> for NumberType
impl From<Number> for NumberType
Source§fn from(val: Number) -> NumberType
fn from(val: Number) -> NumberType
Source§impl NumberLike for Number
impl NumberLike for Number
Source§impl PartialOrd for Number
impl PartialOrd for Number
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Compares two numbers if possible. If either number is not zero and not normal as defined by Rust’s specification, None is returned.
| self sign | other sign | situation |
|---|---|---|
| negative | negative | does comparison (less/equal/greater) |
| negative | positive | less than |
| negative | zero | less than |
| positive | negative | greater than |
| positive | positive | does comparison (less/equal/greater) |
| positive | zero | greater than |
| zero | negative | greater than |
| zero | positive | less than |
| zero | zero | equal |