Introduce a trait constant for the minimum positive normal value
This commit is contained in:
parent
2f0685a9a2
commit
35f5731d62
2 changed files with 10 additions and 0 deletions
|
|
@ -32,6 +32,7 @@ impl Float for f8 {
|
|||
const INFINITY: Self = Self(0b0_1111_000);
|
||||
const NEG_INFINITY: Self = Self(0b1_1111_000);
|
||||
const NAN: Self = Self(0b0_1111_100);
|
||||
const MIN_POSITIVE_NORMAL: Self = Self(1 << Self::SIG_BITS);
|
||||
// FIXME: incorrect values
|
||||
const EPSILON: Self = Self::ZERO;
|
||||
const PI: Self = Self::ZERO;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ pub trait Float:
|
|||
const NEG_PI: Self;
|
||||
const FRAC_PI_2: Self;
|
||||
|
||||
const MIN_POSITIVE_NORMAL: Self;
|
||||
|
||||
/// The bitwidth of the float type
|
||||
const BITS: u32;
|
||||
|
||||
|
|
@ -200,6 +202,9 @@ macro_rules! float_impl {
|
|||
const MIN: Self = $from_bits(Self::Int::MAX & !(1 << Self::SIG_BITS));
|
||||
const EPSILON: Self = <$ty>::EPSILON;
|
||||
|
||||
// Exponent is a 1 in the LSB
|
||||
const MIN_POSITIVE_NORMAL: Self = $from_bits(1 << Self::SIG_BITS);
|
||||
|
||||
const PI: Self = core::$ty::consts::PI;
|
||||
const NEG_PI: Self = -Self::PI;
|
||||
const FRAC_PI_2: Self = core::$ty::consts::FRAC_PI_2;
|
||||
|
|
@ -358,6 +363,7 @@ mod tests {
|
|||
// results for zero and subnormals.
|
||||
assert_eq!(f16::ZERO.exp_unbiased(), -15);
|
||||
assert_eq!(f16::from_bits(0x1).exp_unbiased(), -15);
|
||||
assert_eq!(f16::MIN_POSITIVE, f16::MIN_POSITIVE_NORMAL);
|
||||
|
||||
// `from_parts`
|
||||
assert_biteq!(f16::from_parts(true, f16::EXP_BIAS, 0), -1.0f16);
|
||||
|
|
@ -383,6 +389,7 @@ mod tests {
|
|||
// results for zero and subnormals.
|
||||
assert_eq!(f32::ZERO.exp_unbiased(), -127);
|
||||
assert_eq!(f32::from_bits(0x1).exp_unbiased(), -127);
|
||||
assert_eq!(f32::MIN_POSITIVE, f32::MIN_POSITIVE_NORMAL);
|
||||
|
||||
// `from_parts`
|
||||
assert_biteq!(f32::from_parts(true, f32::EXP_BIAS, 0), -1.0f32);
|
||||
|
|
@ -409,6 +416,7 @@ mod tests {
|
|||
// results for zero and subnormals.
|
||||
assert_eq!(f64::ZERO.exp_unbiased(), -1023);
|
||||
assert_eq!(f64::from_bits(0x1).exp_unbiased(), -1023);
|
||||
assert_eq!(f64::MIN_POSITIVE, f64::MIN_POSITIVE_NORMAL);
|
||||
|
||||
// `from_parts`
|
||||
assert_biteq!(f64::from_parts(true, f64::EXP_BIAS, 0), -1.0f64);
|
||||
|
|
@ -436,6 +444,7 @@ mod tests {
|
|||
// results for zero and subnormals.
|
||||
assert_eq!(f128::ZERO.exp_unbiased(), -16383);
|
||||
assert_eq!(f128::from_bits(0x1).exp_unbiased(), -16383);
|
||||
assert_eq!(f128::MIN_POSITIVE, f128::MIN_POSITIVE_NORMAL);
|
||||
|
||||
// `from_parts`
|
||||
assert_biteq!(f128::from_parts(true, f128::EXP_BIAS, 0), -1.0f128);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue