1 use super::log1pf;
2
3 /* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */
4 /// Inverse hyperbolic tangent (f32)
5 ///
6 /// Calculates the inverse hyperbolic tangent of `x`.
7 /// Is defined as `log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2`.
atanhf(mut x: f32) -> f328 pub fn atanhf(mut x: f32) -> f32 {
9 let mut u = x.to_bits();
10 let sign = (u >> 31) != 0;
11
12 /* |x| */
13 u &= 0x7fffffff;
14 x = f32::from_bits(u);
15
16 if u < 0x3f800000 - (1 << 23) {
17 if u < 0x3f800000 - (32 << 23) {
18 /* handle underflow */
19 if u < (1 << 23) {
20 force_eval!((x * x) as f32);
21 }
22 } else {
23 /* |x| < 0.5, up to 1.7ulp error */
24 x = 0.5 * log1pf(2.0 * x + 2.0 * x * x / (1.0 - x));
25 }
26 } else {
27 /* avoid overflow */
28 x = 0.5 * log1pf(2.0 * (x / (1.0 - x)));
29 }
30
31 if sign {
32 -x
33 } else {
34 x
35 }
36 }
37