Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 59147bd

Browse files
committed
Introduce a trait constant for the minimum positive normal value
1 parent 70db186 commit 59147bd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

libm/crates/libm-test/src/f8_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl Float for f8 {
3232
const INFINITY: Self = Self(0b0_1111_000);
3333
const NEG_INFINITY: Self = Self(0b1_1111_000);
3434
const NAN: Self = Self(0b0_1111_100);
35+
const MIN_POSITIVE_NORMAL: Self = Self(1 << Self::SIG_BITS);
3536
// FIXME: incorrect values
3637
const EPSILON: Self = Self::ZERO;
3738
const PI: Self = Self::ZERO;

libm/src/math/support/float_traits.rs

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub trait Float:
4141
const NEG_PI: Self;
4242
const FRAC_PI_2: Self;
4343

44+
const MIN_POSITIVE_NORMAL: Self;
45+
4446
/// The bitwidth of the float type
4547
const BITS: u32;
4648

@@ -200,6 +202,9 @@ macro_rules! float_impl {
200202
const MIN: Self = $from_bits(Self::Int::MAX & !(1 << Self::SIG_BITS));
201203
const EPSILON: Self = <$ty>::EPSILON;
202204

205+
// Exponent is a 1 in the LSB
206+
const MIN_POSITIVE_NORMAL: Self = $from_bits(1 << Self::SIG_BITS);
207+
203208
const PI: Self = core::$ty::consts::PI;
204209
const NEG_PI: Self = -Self::PI;
205210
const FRAC_PI_2: Self = core::$ty::consts::FRAC_PI_2;
@@ -358,6 +363,7 @@ mod tests {
358363
// results for zero and subnormals.
359364
assert_eq!(f16::ZERO.exp_unbiased(), -15);
360365
assert_eq!(f16::from_bits(0x1).exp_unbiased(), -15);
366+
assert_eq!(f16::MIN_POSITIVE, f16::MIN_POSITIVE_NORMAL);
361367

362368
// `from_parts`
363369
assert_biteq!(f16::from_parts(true, f16::EXP_BIAS, 0), -1.0f16);
@@ -383,6 +389,7 @@ mod tests {
383389
// results for zero and subnormals.
384390
assert_eq!(f32::ZERO.exp_unbiased(), -127);
385391
assert_eq!(f32::from_bits(0x1).exp_unbiased(), -127);
392+
assert_eq!(f32::MIN_POSITIVE, f32::MIN_POSITIVE_NORMAL);
386393

387394
// `from_parts`
388395
assert_biteq!(f32::from_parts(true, f32::EXP_BIAS, 0), -1.0f32);
@@ -409,6 +416,7 @@ mod tests {
409416
// results for zero and subnormals.
410417
assert_eq!(f64::ZERO.exp_unbiased(), -1023);
411418
assert_eq!(f64::from_bits(0x1).exp_unbiased(), -1023);
419+
assert_eq!(f64::MIN_POSITIVE, f64::MIN_POSITIVE_NORMAL);
412420

413421
// `from_parts`
414422
assert_biteq!(f64::from_parts(true, f64::EXP_BIAS, 0), -1.0f64);
@@ -436,6 +444,7 @@ mod tests {
436444
// results for zero and subnormals.
437445
assert_eq!(f128::ZERO.exp_unbiased(), -16383);
438446
assert_eq!(f128::from_bits(0x1).exp_unbiased(), -16383);
447+
assert_eq!(f128::MIN_POSITIVE, f128::MIN_POSITIVE_NORMAL);
439448

440449
// `from_parts`
441450
assert_biteq!(f128::from_parts(true, f128::EXP_BIAS, 0), -1.0f128);

0 commit comments

Comments
 (0)