@@ -27,6 +27,9 @@ trait TestableFloat: Sized {
2727const  NAN_MASK1 :  Self :: Int ; 
2828    /// Second pattern over the mantissa 
2929const  NAN_MASK2 :  Self :: Int ; 
30+     const  EPS_ADD :  Self ; 
31+     const  EPS_MUL :  Self ; 
32+     const  EPS_DIV :  Self ; 
3033} 
3134
3235impl  TestableFloat  for  f16  { 
@@ -44,6 +47,9 @@ impl TestableFloat for f16 {
4447    const  MAX_DOWN :  Self  = Self :: from_bits ( 0x7bfe ) ; 
4548    const  NAN_MASK1 :  Self :: Int  = 0x02aa ; 
4649    const  NAN_MASK2 :  Self :: Int  = 0x0155 ; 
50+     const  EPS_ADD :  Self  = if  cfg ! ( miri)  {  1e1  }  else  {  0.0  } ; 
51+     const  EPS_MUL :  Self  = if  cfg ! ( miri)  {  1e3  }  else  {  0.0  } ; 
52+     const  EPS_DIV :  Self  = if  cfg ! ( miri)  {  1e0  }  else  {  0.0  } ; 
4753} 
4854
4955impl  TestableFloat  for  f32  { 
@@ -63,6 +69,9 @@ impl TestableFloat for f32 {
6369    const  MAX_DOWN :  Self  = Self :: from_bits ( 0x7f7f_fffe ) ; 
6470    const  NAN_MASK1 :  Self :: Int  = 0x002a_aaaa ; 
6571    const  NAN_MASK2 :  Self :: Int  = 0x0055_5555 ; 
72+     const  EPS_ADD :  Self  = if  cfg ! ( miri)  {  1e-3  }  else  {  0.0  } ; 
73+     const  EPS_MUL :  Self  = if  cfg ! ( miri)  {  1e-1  }  else  {  0.0  } ; 
74+     const  EPS_DIV :  Self  = if  cfg ! ( miri)  {  1e-4  }  else  {  0.0  } ; 
6675} 
6776
6877impl  TestableFloat  for  f64  { 
@@ -78,6 +87,9 @@ impl TestableFloat for f64 {
7887    const  MAX_DOWN :  Self  = Self :: from_bits ( 0x7fef_ffff_ffff_fffe ) ; 
7988    const  NAN_MASK1 :  Self :: Int  = 0x000a_aaaa_aaaa_aaaa ; 
8089    const  NAN_MASK2 :  Self :: Int  = 0x0005_5555_5555_5555 ; 
90+     const  EPS_ADD :  Self  = if  cfg ! ( miri)  {  1e-6  }  else  {  0.0  } ; 
91+     const  EPS_MUL :  Self  = if  cfg ! ( miri)  {  1e-6  }  else  {  0.0  } ; 
92+     const  EPS_DIV :  Self  = if  cfg ! ( miri)  {  1e-6  }  else  {  0.0  } ; 
8193} 
8294
8395impl  TestableFloat  for  f128  { 
@@ -93,6 +105,9 @@ impl TestableFloat for f128 {
93105    const  MAX_DOWN :  Self  = Self :: from_bits ( 0x7ffefffffffffffffffffffffffffffe ) ; 
94106    const  NAN_MASK1 :  Self :: Int  = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa ; 
95107    const  NAN_MASK2 :  Self :: Int  = 0x00005555555555555555555555555555 ; 
108+     const  EPS_ADD :  Self  = if  cfg ! ( miri)  {  1e-6  }  else  {  0.0  } ; 
109+     const  EPS_MUL :  Self  = if  cfg ! ( miri)  {  1e-6  }  else  {  0.0  } ; 
110+     const  EPS_DIV :  Self  = if  cfg ! ( miri)  {  1e-6  }  else  {  0.0  } ; 
96111} 
97112
98113/// Determine the tolerance for values of the argument type. 
@@ -1440,3 +1455,27 @@ float_test! {
14401455        assert_biteq!( neg_inf. to_radians( ) ,  neg_inf) ; 
14411456    } 
14421457} 
1458+ 
1459+ float_test !  { 
1460+     name:  to_algebraic, 
1461+     attrs:  { 
1462+         f16:  #[ cfg( target_has_reliable_f16) ] , 
1463+         f128:  #[ cfg( target_has_reliable_f128) ] , 
1464+     } , 
1465+     test<Float > { 
1466+         let  a:  Float  = 123.0 ; 
1467+         let  b:  Float  = 456.0 ; 
1468+ 
1469+         // Check that individual operations match their primitive counterparts. 
1470+         // 
1471+         // This is a check of current implementations and does NOT imply any form of 
1472+         // guarantee about future behavior. The compiler reserves the right to make 
1473+         // these operations inexact matches in the future. 
1474+ 
1475+         assert_approx_eq!( a. algebraic_add( b) ,  a + b,  Float :: EPS_ADD ) ; 
1476+         assert_approx_eq!( a. algebraic_sub( b) ,  a - b,  Float :: EPS_ADD ) ; 
1477+         assert_approx_eq!( a. algebraic_mul( b) ,  a *  b,  Float :: EPS_MUL ) ; 
1478+         assert_approx_eq!( a. algebraic_div( b) ,  a / b,  Float :: EPS_DIV ) ; 
1479+         assert_approx_eq!( a. algebraic_rem( b) ,  a % b,  Float :: EPS_DIV ) ; 
1480+     } 
1481+ } 
0 commit comments