File tree Expand file tree Collapse file tree 2 files changed +6
-10
lines changed Expand file tree Collapse file tree 2 files changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -832,11 +832,7 @@ impl f32 {
832832 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
833833 #[ inline]
834834 pub fn asinh ( self ) -> f32 {
835- if self == Self :: NEG_INFINITY {
836- Self :: NEG_INFINITY
837- } else {
838- ( self + ( ( self * self ) + 1.0 ) . sqrt ( ) ) . ln ( ) . copysign ( self )
839- }
835+ ( self . abs ( ) + ( ( self * self ) + 1.0 ) . sqrt ( ) ) . ln ( ) . copysign ( self )
840836 }
841837
842838 /// Inverse hyperbolic cosine function.
@@ -1413,6 +1409,8 @@ mod tests {
14131409 assert ! ( ( -0.0f32 ) . asinh( ) . is_sign_negative( ) ) ; // issue 63271
14141410 assert_approx_eq ! ( 2.0f32 . asinh( ) , 1.443635475178810342493276740273105f32 ) ;
14151411 assert_approx_eq ! ( ( -2.0f32 ) . asinh( ) , -1.443635475178810342493276740273105f32 ) ;
1412+ // regression test for the catastrophic cancellation fixed in 72486
1413+ assert_approx_eq ! ( ( -3000.0f32 ) . asinh( ) , -8.699514775987968673236893537700647f32 ) ;
14161414 }
14171415
14181416 #[ test]
Original file line number Diff line number Diff line change @@ -834,11 +834,7 @@ impl f64 {
834834 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
835835 #[ inline]
836836 pub fn asinh ( self ) -> f64 {
837- if self == Self :: NEG_INFINITY {
838- Self :: NEG_INFINITY
839- } else {
840- ( self + ( ( self * self ) + 1.0 ) . sqrt ( ) ) . ln ( ) . copysign ( self )
841- }
837+ ( self . abs ( ) + ( ( self * self ) + 1.0 ) . sqrt ( ) ) . ln ( ) . copysign ( self )
842838 }
843839
844840 /// Inverse hyperbolic cosine function.
@@ -1442,6 +1438,8 @@ mod tests {
14421438 // issue 63271
14431439 assert_approx_eq ! ( 2.0f64 . asinh( ) , 1.443635475178810342493276740273105f64 ) ;
14441440 assert_approx_eq ! ( ( -2.0f64 ) . asinh( ) , -1.443635475178810342493276740273105f64 ) ;
1441+ // regression test for the catastrophic cancellation fixed in 72486
1442+ assert_approx_eq ! ( ( -67452098.07139316f64 ) . asinh( ) , -18.72007542627454439398548429400083 ) ;
14451443 }
14461444
14471445 #[ test]
You can’t perform that action at this time.
0 commit comments