• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use super::{log, log1p, sqrt};
2 
3 const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42,  0xfefa39ef*/
4 
5 /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
6 /// Inverse hyperbolic sine (f64)
7 ///
8 /// Calculates the inverse hyperbolic sine of `x`.
9 /// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
asinh(mut x: f64) -> f6410 pub fn asinh(mut x: f64) -> f64 {
11     let mut u = x.to_bits();
12     let e = ((u >> 52) as usize) & 0x7ff;
13     let sign = (u >> 63) != 0;
14 
15     /* |x| */
16     u &= (!0) >> 1;
17     x = f64::from_bits(u);
18 
19     if e >= 0x3ff + 26 {
20         /* |x| >= 0x1p26 or inf or nan */
21         x = log(x) + LN2;
22     } else if e >= 0x3ff + 1 {
23         /* |x| >= 2 */
24         x = log(2.0 * x + 1.0 / (sqrt(x * x + 1.0) + x));
25     } else if e >= 0x3ff - 26 {
26         /* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */
27         x = log1p(x + x * x / (sqrt(x * x + 1.0) + 1.0));
28     } else {
29         /* |x| < 0x1p-26, raise inexact if x != 0 */
30         let x1p120 = f64::from_bits(0x4770000000000000);
31         force_eval!(x + x1p120);
32     }
33 
34     if sign {
35         -x
36     } else {
37         x
38     }
39 }
40