@@ -38,6 +38,8 @@ trait TestableFloat: Sized {
3838 const MUL_ADD_RESULT : Self ;
3939 /// The result of (-12.3).mul_add(-4.5, -6.7)
4040 const NEG_MUL_ADD_RESULT : Self ;
41+ /// Reciprocal of the maximum val
42+ const MAX_RECIP : Self ;
4143}
4244
4345impl TestableFloat for f16 {
@@ -64,6 +66,7 @@ impl TestableFloat for f16 {
6466 const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xcb20 ) ;
6567 const MUL_ADD_RESULT : Self = 62.031 ;
6668 const NEG_MUL_ADD_RESULT : Self = 48.625 ;
69+ const MAX_RECIP : Self = 1.526624e-5 ;
6770}
6871
6972impl TestableFloat for f32 {
@@ -92,6 +95,7 @@ impl TestableFloat for f32 {
9295 const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xc1640000 ) ;
9396 const MUL_ADD_RESULT : Self = 62.05 ;
9497 const NEG_MUL_ADD_RESULT : Self = 48.65 ;
98+ const MAX_RECIP : Self = 2.938736e-39 ;
9599}
96100
97101impl TestableFloat for f64 {
@@ -116,6 +120,7 @@ impl TestableFloat for f64 {
116120 const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xc02c800000000000 ) ;
117121 const MUL_ADD_RESULT : Self = 62.050000000000004 ;
118122 const NEG_MUL_ADD_RESULT : Self = 48.650000000000006 ;
123+ const MAX_RECIP : Self = 5.562684646268003e-309 ;
119124}
120125
121126impl TestableFloat for f128 {
@@ -140,6 +145,7 @@ impl TestableFloat for f128 {
140145 const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xc002c800000000000000000000000000 ) ;
141146 const MUL_ADD_RESULT : Self = 62.0500000000000000000000000000000037 ;
142147 const NEG_MUL_ADD_RESULT : Self = 48.6500000000000000000000000000000049 ;
148+ const MAX_RECIP : Self = 8.40525785778023376565669454330438228902076605e-4933 ;
143149}
144150
145151/// Determine the tolerance for values of the argument type.
@@ -1425,13 +1431,15 @@ float_test! {
14251431 let nan: Float = Float :: NAN ;
14261432 let inf: Float = Float :: INFINITY ;
14271433 let neg_inf: Float = Float :: NEG_INFINITY ;
1434+ let max: Float = Float :: MAX ;
14281435 assert_biteq!( ( 1.0 as Float ) . recip( ) , 1.0 ) ;
14291436 assert_biteq!( ( 2.0 as Float ) . recip( ) , 0.5 ) ;
14301437 assert_biteq!( ( -0.4 as Float ) . recip( ) , -2.5 ) ;
14311438 assert_biteq!( ( 0.0 as Float ) . recip( ) , inf) ;
14321439 assert!( nan. recip( ) . is_nan( ) ) ;
14331440 assert_biteq!( inf. recip( ) , 0.0 ) ;
14341441 assert_biteq!( neg_inf. recip( ) , -0.0 ) ;
1442+ assert_biteq!( max. recip( ) , Float :: MAX_RECIP ) ;
14351443 }
14361444}
14371445
0 commit comments