pub enum FloatKind {
NaN,
Zero,
Normal(u64, u32, bool),
Overflow(bool),
Infinity,
}Expand description
§Float Type.
This enum provides basic float classification. It is used by NiceFloat
for formatting, but may be useful in other contexts too. Enjoy!
§Examples
use dactyl::FloatKind;
// Weird things.
assert_eq!(FloatKind::from(f64::NAN), FloatKind::NaN);
assert_eq!(FloatKind::from(f64::INFINITY), FloatKind::Infinity);
assert_eq!(FloatKind::from(f64::NEG_INFINITY), FloatKind::Infinity);
// Really big or small values can't be parsed out.
assert_eq!(FloatKind::from(f64::MIN), FloatKind::Overflow(true));
assert_eq!(FloatKind::from(f64::MAX), FloatKind::Overflow(false));
// Normal things.
assert_eq!(FloatKind::from(0_f32), FloatKind::Zero);
assert_eq!(FloatKind::from(123.456_f64), FloatKind::Normal(123, 45600000, false));
assert_eq!(FloatKind::from(-123.456_f64), FloatKind::Normal(123, 45600000, true));As mentioned elsewhere, Rust floats are imprecise. Any imprecision within
the original float will come through in the parsed FloatKind.
use dactyl::FloatKind;
// This is right, but wrong. Haha.
assert_eq!(
FloatKind::from(1234.5678_f32),
FloatKind::Normal(1234, 56774902, false),
);Variants§
NaN
§Not a Number.
Zero
§Zero.
This does not differentiate between positive and negative zero; they’re just zero…
Normal(u64, u32, bool)
§Normal.
This holds the integer and fractional parts of the float, along with a bool indicating whether or not it was negative.
The integer range must fit within u64; larger (absolute) values will
fall back to FloatKind::Overflow.
The fractional range holds up to eight digits, rounding on the ninth using a tie-to-even strategy.
Overflow(bool)
§Overflow.
The value is normal, but is too big to be nicely split. The bool indicates whether or not the value is negative.
Infinity
§Infinity.
This does not differentiate between positive and negative infinity; the point is the numbers go on and on and on…