@@ -19,6 +19,31 @@ impl Approx for f128 {
1919 const LIM : Self = 1e-9 ;
2020}
2121
22+ trait TestableFloat {
23+ const SMALL_NORMAL : Self ;
24+ const SUBNORMAL : Self ;
25+ }
26+
27+ impl TestableFloat for f16 {
28+ const SMALL_NORMAL : Self = 1e-4 ;
29+ const SUBNORMAL : Self = 1e-5 ;
30+ }
31+
32+ impl TestableFloat for f32 {
33+ const SMALL_NORMAL : Self = 1e-37 ;
34+ const SUBNORMAL : Self = 1e-38 ;
35+ }
36+
37+ impl TestableFloat for f64 {
38+ const SMALL_NORMAL : Self = 1e-307 ;
39+ const SUBNORMAL : Self = 1e-308 ;
40+ }
41+
42+ impl TestableFloat for f128 {
43+ const SMALL_NORMAL : Self = 1e-4931 ;
44+ const SUBNORMAL : Self = 1e-4932 ;
45+ }
46+
2247/// Determine the tolerance for values of the argument type.
2348const fn lim_for_ty < T : Approx + Copy > ( _x : T ) -> T {
2449 T :: LIM
@@ -186,7 +211,7 @@ macro_rules! float_test {
186211 $( $( #[ $const_meta] ) + ) ?
187212 mod const_ {
188213 #[ allow( unused) ]
189- use super :: Approx ;
214+ use super :: { Approx , TestableFloat } ;
190215 #[ allow( unused) ]
191216 use std:: num:: FpCategory as Fp ;
192217 #[ allow( unused) ]
@@ -443,6 +468,30 @@ float_test! {
443468 }
444469}
445470
471+ float_test ! {
472+ name: is_normal,
473+ attrs: {
474+ f16: #[ cfg( any( miri, target_has_reliable_f16) ) ] ,
475+ f128: #[ cfg( any( miri, target_has_reliable_f128) ) ] ,
476+ } ,
477+ test<Float > {
478+ let nan: Float = Float :: NAN ;
479+ let inf: Float = Float :: INFINITY ;
480+ let neg_inf: Float = Float :: NEG_INFINITY ;
481+ let zero: Float = 0.0 ;
482+ let neg_zero: Float = -0.0 ;
483+ let one : Float = 1.0 ;
484+ assert!( !nan. is_normal( ) ) ;
485+ assert!( !inf. is_normal( ) ) ;
486+ assert!( !neg_inf. is_normal( ) ) ;
487+ assert!( !zero. is_normal( ) ) ;
488+ assert!( !neg_zero. is_normal( ) ) ;
489+ assert!( one. is_normal( ) ) ;
490+ assert!( Float :: SMALL_NORMAL . is_normal( ) ) ;
491+ assert!( !Float :: SUBNORMAL . is_normal( ) ) ;
492+ }
493+ }
494+
446495float_test ! {
447496 name: min,
448497 attrs: {
0 commit comments