math: use 0x1p-120f and 0x1p120f for tiny and huge values
[musl] / src / math / asinhl.c
1 #include "libm.h"
2
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4 long double asinhl(long double x)
5 {
6         return asinh(x);
7 }
8 #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) */
10 long double asinhl(long double x)
11 {
12         union {
13                 long double f;
14                 struct{uint64_t m; uint16_t se; uint16_t pad;} i;
15         } u = {.f = x};
16         unsigned e = u.i.se & 0x7fff;
17         unsigned s = u.i.se >> 15;
18
19         /* |x| */
20         u.i.se = e;
21         x = u.f;
22
23         if (e >= 0x3fff + 32) {
24                 /* |x| >= 0x1p32 or inf or nan */
25                 x = logl(x) + 0.693147180559945309417232121458176568L;
26         } else if (e >= 0x3fff + 1) {
27                 /* |x| >= 2 */
28                 x = logl(2*x + 1/(sqrtl(x*x+1)+x));
29         } else if (e >= 0x3fff - 32) {
30                 /* |x| >= 0x1p-32 */
31                 x = log1pl(x + x*x/(sqrtl(x*x+1)+1));
32         } else {
33                 /* |x| < 0x1p-32, raise inexact if x!=0 */
34                 FORCE_EVAL(x + 0x1p120f);
35         }
36         return s ? -x : x;
37 }
38 #endif