pub struct Float { /* private fields */ }
Expand description
A custom floating-point number representation that separates the number into its fundamental components for more precise comparison operations.
Implementations§
Source§impl Float
impl Float
pub const ZERO: Float
pub const ONE: Float
pub const TWO: Float
Sourcepub fn from_f64(value: f64) -> Option<Self>
pub fn from_f64(value: f64) -> Option<Self>
Creates a new Float
from a f64
value.
This method decomposes the floating-point number into its constituent parts, normalizing the mantissa to remove trailing zeros and adjusting the exponent accordingly.
§Arguments
value
- The floating-pointf64
number to decompose.
§Returns
A Float
representation of the input number.
§Example
use fast_float_compare::Float;
let num = Float::from_f64(1.23);
assert!(num.is_some());
§Errors
Returns None
if the number is NaN or infinite.
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
Converts a Float
back to an f64
.
This method reconstructs the original floating-point number from its mantissa, exponent, and sign components.
§Example
use fast_float_compare::Float;
let num = Float::from_f64(1.23).unwrap();
let value = num.to_f64();
assert_eq!(value, 1.23);
§Returns
The reconstructed f64
value.
Trait Implementations§
Source§impl Ord for Float
Implements the Ord
trait for Float
.
This trait allows for comparison between Float
values.
impl Ord for Float
Implements the Ord
trait for Float
.
This trait allows for comparison between Float
values.
§Example
use fast_float_compare::Float;
let a = Float::from_f64(1.23).unwrap();
let b = Float::from_f64(4.56).unwrap();
assert!(a < b);
Source§impl PartialOrd for Float
impl PartialOrd for Float
impl Copy for Float
impl Eq for Float
impl StructuralPartialEq for Float
Auto Trait Implementations§
impl Freeze for Float
impl RefUnwindSafe for Float
impl Send for Float
impl Sync for Float
impl Unpin for Float
impl UnwindSafe for Float
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