File tree Expand file tree Collapse file tree 4 files changed +20
-42
lines changed
Expand file tree Collapse file tree 4 files changed +20
-42
lines changed Original file line number Diff line number Diff line change @@ -832,13 +832,7 @@ impl f16 {
832832 #[ unstable( feature = "f16" , issue = "116909" ) ]
833833 #[ must_use = "method returns a new number and does not mutate the original value" ]
834834 pub fn asinh ( self ) -> f16 {
835- let ax = self . abs ( ) ;
836- if ax >= ( 1u16 << f16:: MANTISSA_DIGITS / 2 ) as f16 {
837- return ( ax. ln ( ) + consts:: LN_2 ) . copysign ( self ) ;
838- }
839-
840- let ix = 1.0 / ax;
841- ( ax + ( ax / ( Self :: hypot ( 1.0 , ix) + ix) ) ) . ln_1p ( ) . copysign ( self )
835+ cmath:: asinhf ( self as f32 ) as f16
842836 }
843837
844838 /// Inverse hyperbolic cosine function.
@@ -869,13 +863,7 @@ impl f16 {
869863 #[ unstable( feature = "f16" , issue = "116909" ) ]
870864 #[ must_use = "method returns a new number and does not mutate the original value" ]
871865 pub fn acosh ( self ) -> f16 {
872- if self < 1.0 {
873- Self :: NAN
874- } else if self >= ( 1u16 << f16:: MANTISSA_DIGITS / 2 ) as f16 {
875- self . ln ( ) + consts:: LN_2
876- } else {
877- ( self + ( ( self - 1.0 ) . sqrt ( ) * ( self + 1.0 ) . sqrt ( ) ) ) . ln ( )
878- }
866+ cmath:: acoshf ( self as f32 ) as f16
879867 }
880868
881869 /// Inverse hyperbolic tangent function.
Original file line number Diff line number Diff line change @@ -1091,13 +1091,7 @@ impl f32 {
10911091 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
10921092 #[ inline]
10931093 pub fn asinh ( self ) -> f32 {
1094- let ax = self . abs ( ) ;
1095- if ax >= ( 1u32 << f32:: MANTISSA_DIGITS / 2 ) as f32 {
1096- return ( ax. ln ( ) + consts:: LN_2 ) . copysign ( self ) ;
1097- }
1098-
1099- let ix = 1.0 / ax;
1100- ( ax + ( ax / ( Self :: hypot ( 1.0 , ix) + ix) ) ) . ln_1p ( ) . copysign ( self )
1094+ cmath:: asinhf ( self )
11011095 }
11021096
11031097 /// Inverse hyperbolic cosine function.
@@ -1123,13 +1117,7 @@ impl f32 {
11231117 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
11241118 #[ inline]
11251119 pub fn acosh ( self ) -> f32 {
1126- if self < 1.0 {
1127- Self :: NAN
1128- } else if self >= ( 1u32 << f32:: MANTISSA_DIGITS / 2 ) as f32 {
1129- self . ln ( ) + consts:: LN_2
1130- } else {
1131- ( self + ( ( self - 1.0 ) . sqrt ( ) * ( self + 1.0 ) . sqrt ( ) ) ) . ln ( )
1132- }
1120+ cmath:: acoshf ( self )
11331121 }
11341122
11351123 /// Inverse hyperbolic tangent function.
Original file line number Diff line number Diff line change @@ -1091,13 +1091,7 @@ impl f64 {
10911091 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
10921092 #[ inline]
10931093 pub fn asinh ( self ) -> f64 {
1094- let ax = self . abs ( ) ;
1095- if ax >= ( 1u64 << f64:: MANTISSA_DIGITS / 2 ) as f64 {
1096- return ( ax. ln ( ) + consts:: LN_2 ) . copysign ( self ) ;
1097- }
1098-
1099- let ix = 1.0 / ax;
1100- ( ax + ( ax / ( Self :: hypot ( 1.0 , ix) + ix) ) ) . ln_1p ( ) . copysign ( self )
1094+ cmath:: asinh ( self )
11011095 }
11021096
11031097 /// Inverse hyperbolic cosine function.
@@ -1123,13 +1117,7 @@ impl f64 {
11231117 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
11241118 #[ inline]
11251119 pub fn acosh ( self ) -> f64 {
1126- if self < 1.0 {
1127- Self :: NAN
1128- } else if self >= ( 1u64 << f64:: MANTISSA_DIGITS / 2 ) as f64 {
1129- self . ln ( ) + consts:: LN_2
1130- } else {
1131- ( self + ( ( self - 1.0 ) . sqrt ( ) * ( self + 1.0 ) . sqrt ( ) ) ) . ln ( )
1132- }
1120+ cmath:: acosh ( self )
11331121 }
11341122
11351123 /// Inverse hyperbolic tangent function.
Original file line number Diff line number Diff line change 44// or by `compiler-builtins` on unsupported platforms.
55unsafe extern "C" {
66 pub safe fn acos ( n : f64 ) -> f64 ;
7+ pub safe fn acosh ( n : f64 ) -> f64 ;
78 pub safe fn asin ( n : f64 ) -> f64 ;
9+ pub safe fn asinh ( n : f64 ) -> f64 ;
810 pub safe fn atan ( n : f64 ) -> f64 ;
911 pub safe fn atan2 ( a : f64 , b : f64 ) -> f64 ;
1012 pub safe fn cosh ( n : f64 ) -> f64 ;
@@ -57,6 +59,16 @@ cfg_select! {
5759 f64 :: acos( n as f64 ) as f32
5860 }
5961
62+ #[ inline]
63+ pub fn acoshf( n: f32 ) -> f32 {
64+ f64 :: acosh( n as f64 ) as f32
65+ }
66+
67+ #[ inline]
68+ pub fn asinhf( n: f32 ) -> f32 {
69+ f64 :: asinh( n as f64 ) as f32
70+ }
71+
6072 #[ inline]
6173 pub fn asinf( n: f32 ) -> f32 {
6274 f64 :: asin( n as f64 ) as f32
@@ -95,7 +107,9 @@ cfg_select! {
95107 _ => {
96108 unsafe extern "C" {
97109 pub safe fn acosf( n: f32 ) -> f32 ;
110+ pub safe fn acoshf( n: f32 ) -> f32 ;
98111 pub safe fn asinf( n: f32 ) -> f32 ;
112+ pub safe fn asinhf( n: f32 ) -> f32 ;
99113 pub safe fn atan2f( a: f32 , b: f32 ) -> f32 ;
100114 pub safe fn atanf( n: f32 ) -> f32 ;
101115 pub safe fn coshf( n: f32 ) -> f32 ;
You can’t perform that action at this time.
0 commit comments