@@ -2,6 +2,9 @@ use std::hint::black_box;
22use std:: num:: FpCategory as Fp ;
33use std:: ops:: { Add , Div , Mul , Rem , Sub } ;
44
5+ /// i586 has issues with floating point precision.
6+ const I586 : bool = cfg ! ( target_arch = "x86" ) && cfg ! ( not( target_feature = "sse2" ) ) ;
7+
58pub ( crate ) trait TestableFloat : Sized {
69 const BITS : u32 ;
710 /// Unsigned int with the same size, for converting to/from bits.
@@ -59,6 +62,7 @@ pub(crate) trait TestableFloat: Sized {
5962 const NEG_MUL_ADD_RESULT : Self ;
6063 /// Reciprocal of the maximum val
6164 const MAX_RECIP : Self ;
65+ const ASINH_ACOSH_MAX : Self ;
6266}
6367
6468impl TestableFloat for f16 {
@@ -103,6 +107,7 @@ impl TestableFloat for f16 {
103107 const MUL_ADD_RESULT : Self = 62.031 ;
104108 const NEG_MUL_ADD_RESULT : Self = 48.625 ;
105109 const MAX_RECIP : Self = 1.526624e-5 ;
110+ const ASINH_ACOSH_MAX : Self = 11.781 ;
106111}
107112
108113impl TestableFloat for f32 {
@@ -120,8 +125,20 @@ impl TestableFloat for f32 {
120125 const LOG_APPROX : Self = if cfg ! ( miri) { 1e-3 } else { Self :: APPROX } ;
121126 const LOG2_APPROX : Self = if cfg ! ( miri) { 1e-3 } else { Self :: APPROX } ;
122127 const LOG10_APPROX : Self = if cfg ! ( miri) { 1e-3 } else { Self :: APPROX } ;
123- const ASINH_APPROX : Self = if cfg ! ( miri) { 1e-3 } else { Self :: APPROX } ;
124- const ACOSH_APPROX : Self = if cfg ! ( miri) { 1e-3 } else { Self :: APPROX } ;
128+ const ASINH_APPROX : Self = if cfg ! ( miri) {
129+ 1e-3
130+ } else if I586 {
131+ 1e-5
132+ } else {
133+ Self :: APPROX
134+ } ;
135+ const ACOSH_APPROX : Self = if cfg ! ( miri) {
136+ 1e-3
137+ } else if I586 {
138+ 1e-5
139+ } else {
140+ Self :: APPROX
141+ } ;
125142 const ATANH_APPROX : Self = if cfg ! ( miri) { 1e-3 } else { Self :: APPROX } ;
126143 const GAMMA_APPROX : Self = if cfg ! ( miri) { 1e-3 } else { Self :: APPROX } ;
127144 const GAMMA_APPROX_LOOSE : Self = if cfg ! ( miri) { 1e-2 } else { 1e-4 } ;
@@ -149,6 +166,7 @@ impl TestableFloat for f32 {
149166 const MUL_ADD_RESULT : Self = 62.05 ;
150167 const NEG_MUL_ADD_RESULT : Self = 48.65 ;
151168 const MAX_RECIP : Self = 2.938736e-39 ;
169+ const ASINH_ACOSH_MAX : Self = 89.4159851 ;
152170}
153171
154172impl TestableFloat for f64 {
@@ -180,6 +198,7 @@ impl TestableFloat for f64 {
180198 const MUL_ADD_RESULT : Self = 62.050000000000004 ;
181199 const NEG_MUL_ADD_RESULT : Self = 48.650000000000006 ;
182200 const MAX_RECIP : Self = 5.562684646268003e-309 ;
201+ const ASINH_ACOSH_MAX : Self = 710.47586007394398 ;
183202}
184203
185204impl TestableFloat for f128 {
@@ -221,6 +240,7 @@ impl TestableFloat for f128 {
221240 const MUL_ADD_RESULT : Self = 62.0500000000000000000000000000000037 ;
222241 const NEG_MUL_ADD_RESULT : Self = 48.6500000000000000000000000000000049 ;
223242 const MAX_RECIP : Self = 8.40525785778023376565669454330438228902076605e-4933 ;
243+ const ASINH_ACOSH_MAX : Self = 11357.216553474703894801348310092223 ;
224244}
225245
226246/// Determine the tolerance for values of the argument type.
@@ -1705,6 +1725,9 @@ float_test! {
17051725
17061726 assert_approx_eq!( flt( -200.0 ) . asinh( ) , -5.991470797049389 , Float :: ASINH_APPROX ) ;
17071727
1728+ // issue 153878: large values were rounding to infinity
1729+ assert_approx_eq!( Float :: MAX . asinh( ) , Float :: ASINH_ACOSH_MAX , Float :: ASINH_APPROX ) ;
1730+
17081731 #[ allow( overflowing_literals) ]
17091732 if Float :: MAX > flt( 66000.0 ) {
17101733 // regression test for the catastrophic cancellation fixed in 72486
@@ -1733,6 +1756,9 @@ float_test! {
17331756 assert_approx_eq!( flt( 2.0 ) . acosh( ) , 1.31695789692481670862504634730796844 , Float :: ACOSH_APPROX ) ;
17341757 assert_approx_eq!( flt( 3.0 ) . acosh( ) , 1.76274717403908605046521864995958461 , Float :: ACOSH_APPROX ) ;
17351758
1759+ // issue 153878: large values were rounding to infinity
1760+ assert_approx_eq!( Float :: MAX . acosh( ) , Float :: ASINH_ACOSH_MAX , Float :: ACOSH_APPROX ) ;
1761+
17361762 #[ allow( overflowing_literals) ]
17371763 if Float :: MAX > flt( 66000.0 ) {
17381764 // test for low accuracy from issue 104548
0 commit comments