OLD | NEW |
1 #include "libm.h" | 1 #include "libm.h" |
2 | 2 |
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | 3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
4 long double asinhl(long double x) | 4 long double asinhl(long double x) { |
5 { | 5 return asinh(x); |
6 » return asinh(x); | |
7 } | 6 } |
8 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | 7 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 |
9 /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ | 8 /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ |
10 long double asinhl(long double x) | 9 long double asinhl(long double x) { |
11 { | 10 union ldshape u = {x}; |
12 » union ldshape u = {x}; | 11 unsigned e = u.i.se & 0x7fff; |
13 » unsigned e = u.i.se & 0x7fff; | 12 unsigned s = u.i.se >> 15; |
14 » unsigned s = u.i.se >> 15; | |
15 | 13 |
16 » /* |x| */ | 14 /* |x| */ |
17 » u.i.se = e; | 15 u.i.se = e; |
18 » x = u.f; | 16 x = u.f; |
19 | 17 |
20 » if (e >= 0x3fff + 32) { | 18 if (e >= 0x3fff + 32) { |
21 » » /* |x| >= 0x1p32 or inf or nan */ | 19 /* |x| >= 0x1p32 or inf or nan */ |
22 » » x = logl(x) + 0.693147180559945309417232121458176568L; | 20 x = logl(x) + 0.693147180559945309417232121458176568L; |
23 » } else if (e >= 0x3fff + 1) { | 21 } else if (e >= 0x3fff + 1) { |
24 » » /* |x| >= 2 */ | 22 /* |x| >= 2 */ |
25 » » x = logl(2*x + 1/(sqrtl(x*x+1)+x)); | 23 x = logl(2 * x + 1 / (sqrtl(x * x + 1) + x)); |
26 » } else if (e >= 0x3fff - 32) { | 24 } else if (e >= 0x3fff - 32) { |
27 » » /* |x| >= 0x1p-32 */ | 25 /* |x| >= 0x1p-32 */ |
28 » » x = log1pl(x + x*x/(sqrtl(x*x+1)+1)); | 26 x = log1pl(x + x * x / (sqrtl(x * x + 1) + 1)); |
29 » } else { | 27 } else { |
30 » » /* |x| < 0x1p-32, raise inexact if x!=0 */ | 28 /* |x| < 0x1p-32, raise inexact if x!=0 */ |
31 » » FORCE_EVAL(x + 0x1p120f); | 29 FORCE_EVAL(x + 0x1p120f); |
32 » } | 30 } |
33 » return s ? -x : x; | 31 return s ? -x : x; |
34 } | 32 } |
35 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | 33 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 |
36 // TODO: broken implementation to make things compile | 34 // TODO: broken implementation to make things compile |
37 long double asinhl(long double x) | 35 long double asinhl(long double x) { |
38 { | 36 return asinh(x); |
39 » return asinh(x); | |
40 } | 37 } |
41 #endif | 38 #endif |
OLD | NEW |