@@ -38,6 +38,9 @@ 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 value and an acceptable precision
42+ const MAX_RECIP : Self = Self :: APPROX ;
43+ const MAX_RECIP_APPROX : Self = Self :: APPROX ;
4144}
4245
4346impl TestableFloat for f16 {
@@ -64,6 +67,8 @@ impl TestableFloat for f16 {
6467 const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xcb20 ) ;
6568 const MUL_ADD_RESULT : Self = 62.031 ;
6669 const NEG_MUL_ADD_RESULT : Self = 48.625 ;
70+ const MAX_RECIP : Self = 1.526624e-5f16 ;
71+ const MAX_RECIP_APPROX : Self = 1e-4 ;
6772}
6873
6974impl TestableFloat for f32 {
@@ -140,6 +145,8 @@ 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 ;
149+ const MAX_RECIP_APPROX : Self = 1e-4900 ;
143150}
144151
145152/// Determine the tolerance for values of the argument type.
@@ -1574,3 +1581,14 @@ float_test! {
15741581 assert_biteq!( ( flt( -3.2 ) ) . mul_add( 2.4 , neg_inf) , neg_inf) ;
15751582 }
15761583}
1584+
1585+ float_test ! {
1586+ name: max_recip,
1587+ attrs: {
1588+ f16: #[ cfg( any( miri, target_has_reliable_f16_math) ) ] ,
1589+ f128: #[ cfg( any( miri, target_has_reliable_f128_math) ) ] ,
1590+ } ,
1591+ test<Float > {
1592+ assert_approx_eq!( Float :: MAX . recip( ) , Float :: MAX_RECIP , Float :: MAX_RECIP_APPROX ) ;
1593+ }
1594+ }
0 commit comments