Struct rug::float::OrdFloat [−][src]
#[repr(transparent)]pub struct OrdFloat { /* fields omitted */ }
Expand description
A float that supports total ordering and hashing.
Negative zero is ordered as less than positive zero. Negative NaN is ordered as less than negative infinity, while positive NaN is ordered as greater than positive infinity. Comparing two negative NaNs or two positive NaNs produces equality.
Examples
use core::cmp::Ordering; use rug::{ float::{OrdFloat, Special}, Float, }; let pos_nan_f = Float::with_val(53, Special::Nan); let pos_inf_f = Float::with_val(53, Special::Infinity); let pos_zero_f = Float::with_val(53, Special::Zero); let neg_zero_f = Float::with_val(53, Special::NegZero); let neg_inf_f = Float::with_val(53, Special::NegInfinity); let neg_nan_f = Float::with_val(53, -&pos_nan_f); let pos_nan = OrdFloat::from(pos_nan_f); let pos_inf = OrdFloat::from(pos_inf_f); let pos_zero = OrdFloat::from(pos_zero_f); let neg_zero = OrdFloat::from(neg_zero_f); let neg_inf = OrdFloat::from(neg_inf_f); let neg_nan = OrdFloat::from(neg_nan_f); assert_eq!(pos_nan.cmp(&pos_nan), Ordering::Equal); assert_eq!(neg_nan.cmp(&neg_nan), Ordering::Equal); assert_eq!(neg_nan.cmp(&pos_nan), Ordering::Less); assert_eq!(pos_nan.cmp(&pos_inf), Ordering::Greater); assert_eq!(neg_nan.cmp(&neg_inf), Ordering::Less); assert_eq!(pos_zero.cmp(&neg_zero), Ordering::Greater);
Implementations
Extracts the underlying Float
.
The same result can be obtained using the implementation of
AsRef<Float>
which is provided for
OrdFloat
.
Examples
use rug::{float::OrdFloat, Float}; let f = Float::with_val(53, 1.5); let ord = OrdFloat::from(f); let f_ref = ord.as_float(); assert_eq!(f_ref.to_f64(), 1.5);
Extracts the underlying Float
.
The same result can be obtained using the implementation of
AsMut<Float>
which is provided for
OrdFloat
.
Examples
use rug::{float::OrdFloat, Float}; let f = Float::with_val(53, -1.5); let mut ord = OrdFloat::from(f); ord.as_float_mut().abs_mut(); assert_eq!(ord.as_float().to_f64(), 1.5);
Trait Implementations
Deserialize this value from the given Serde deserializer. Read more
fn deserialize_in_place<D: Deserializer<'de>>(
deserializer: D,
place: &mut OrdFloat
) -> Result<(), D::Error>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for OrdFloat
impl UnwindSafe for OrdFloat
Blanket Implementations
Mutably borrows from an owned value. Read more
Casts the value.
Casts the value.
Casts the value.
Casts the value.
Casts the value.