decompose_float/
lib.rs

1#![cfg_attr(feature = "f16", feature(f16))]
2#![cfg_attr(feature = "f128", feature(f128))]
3
4mod fmt;
5mod ieee754;
6
7#[cfg(test)]
8mod tests;
9
10/// It's literally `DecomposeResult`, not a number. If it were a number,
11/// `Zero` and `NegZero` has to be equal. But they're not equal because they're
12/// results of decompositions of different bit patterns.
13/// Also, that's why it implements `Eq` but not `Ord`.
14#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
15pub enum DecomposeResult {
16    /// `n = (-1)^is_neg * 2^exp * mantissa / 2^127`
17    ///
18    /// always `2^127 <= mantissa < 2^128`
19    Normal {
20        is_neg: bool,
21        exp: i32,
22        mantissa: u128,
23    },
24    Zero,
25    NegZero,
26    Infinity,
27    NegInfinity,
28
29    /// It treats NaNs equal, and that's intentional. IEEE754 treats NaNs unequal because
30    /// NaN is an indicator of an invalid operation. Here, `DecomposeResult::NotANumber` is
31    /// a result of a successful `n.decompose()`, so it has to implement `Eq`.
32    NotANumber,
33}
34
35pub trait Decompose {
36    fn decompose(&self) -> DecomposeResult;
37}