1 use super::{log1pf, logf, sqrtf}; 2 3 const LN2: f32 = 0.693147180559945309417232121458176568; 4 5 /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ 6 /// Inverse hyperbolic sine (f32) 7 /// 8 /// Calculates the inverse hyperbolic sine of `x`. 9 /// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`. asinhf(mut x: f32) -> f3210pub fn asinhf(mut x: f32) -> f32 { 11 let u = x.to_bits(); 12 let i = u & 0x7fffffff; 13 let sign = (u >> 31) != 0; 14 15 /* |x| */ 16 x = f32::from_bits(i); 17 18 if i >= 0x3f800000 + (12 << 23) { 19 /* |x| >= 0x1p12 or inf or nan */ 20 x = logf(x) + LN2; 21 } else if i >= 0x3f800000 + (1 << 23) { 22 /* |x| >= 2 */ 23 x = logf(2.0 * x + 1.0 / (sqrtf(x * x + 1.0) + x)); 24 } else if i >= 0x3f800000 - (12 << 23) { 25 /* |x| >= 0x1p-12, up to 1.6ulp error in [0.125,0.5] */ 26 x = log1pf(x + x * x / (sqrtf(x * x + 1.0) + 1.0)); 27 } else { 28 /* |x| < 0x1p-12, raise inexact if x!=0 */ 29 let x1p120 = f32::from_bits(0x7b800000); 30 force_eval!(x + x1p120); 31 } 32 33 if sign { 34 -x 35 } else { 36 x 37 } 38 } 39