| OLD | NEW |
| 1 #include "libm.h" | 1 #include "libm.h" |
| 2 | 2 |
| 3 /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ | 3 /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ |
| 4 double asinh(double x) | 4 double asinh(double x) { |
| 5 { | 5 union { |
| 6 » union {double f; uint64_t i;} u = {.f = x}; | 6 double f; |
| 7 » unsigned e = u.i >> 52 & 0x7ff; | 7 uint64_t i; |
| 8 » unsigned s = u.i >> 63; | 8 } u = {.f = x}; |
| 9 unsigned e = u.i >> 52 & 0x7ff; |
| 10 unsigned s = u.i >> 63; |
| 9 | 11 |
| 10 » /* |x| */ | 12 /* |x| */ |
| 11 » u.i &= (uint64_t)-1/2; | 13 u.i &= (uint64_t)-1 / 2; |
| 12 » x = u.f; | 14 x = u.f; |
| 13 | 15 |
| 14 » if (e >= 0x3ff + 26) { | 16 if (e >= 0x3ff + 26) { |
| 15 » » /* |x| >= 0x1p26 or inf or nan */ | 17 /* |x| >= 0x1p26 or inf or nan */ |
| 16 » » x = log(x) + 0.693147180559945309417232121458176568; | 18 x = log(x) + 0.693147180559945309417232121458176568; |
| 17 » } else if (e >= 0x3ff + 1) { | 19 } else if (e >= 0x3ff + 1) { |
| 18 » » /* |x| >= 2 */ | 20 /* |x| >= 2 */ |
| 19 » » x = log(2*x + 1/(sqrt(x*x+1)+x)); | 21 x = log(2 * x + 1 / (sqrt(x * x + 1) + x)); |
| 20 » } else if (e >= 0x3ff - 26) { | 22 } else if (e >= 0x3ff - 26) { |
| 21 » » /* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */ | 23 /* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */ |
| 22 » » x = log1p(x + x*x/(sqrt(x*x+1)+1)); | 24 x = log1p(x + x * x / (sqrt(x * x + 1) + 1)); |
| 23 » } else { | 25 } else { |
| 24 » » /* |x| < 0x1p-26, raise inexact if x != 0 */ | 26 /* |x| < 0x1p-26, raise inexact if x != 0 */ |
| 25 » » FORCE_EVAL(x + 0x1p120f); | 27 FORCE_EVAL(x + 0x1p120f); |
| 26 » } | 28 } |
| 27 » return s ? -x : x; | 29 return s ? -x : x; |
| 28 } | 30 } |
| OLD | NEW |