math: add fma TODO comments about the underflow issue
[oweals/musl.git] / src / math / coshl.c
1 #include "libm.h"
2
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4 long double coshl(long double x)
5 {
6         return cosh(x);
7 }
8 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
9 long double coshl(long double x)
10 {
11         union {
12                 long double f;
13                 struct{uint64_t m; uint16_t se; uint16_t pad;} i;
14         } u = {.f = x};
15         unsigned ex = u.i.se & 0x7fff;
16         uint32_t w;
17         long double t;
18
19         /* |x| */
20         u.i.se = ex;
21         x = u.f;
22         w = u.i.m >> 32;
23
24         /* |x| < log(2) */
25         if (ex < 0x3fff-1 || (ex == 0x3fff-1 && w < 0xb17217f7)) {
26                 if (ex < 0x3fff-32) {
27                         FORCE_EVAL(x + 0x1p120f);
28                         return 1;
29                 }
30                 t = expm1l(x);
31                 return 1 + t*t/(2*(1+t));
32         }
33
34         /* |x| < log(LDBL_MAX) */
35         if (ex < 0x3fff+13 || (ex == 0x3fff+13 && w < 0xb17217f7)) {
36                 t = expl(x);
37                 return 0.5*(t + 1/t);
38         }
39
40         /* |x| > log(LDBL_MAX) or nan */
41         t = expl(0.5*x);
42         return 0.5*t*t;
43 }
44 #endif