1#include "libm.h"
2
3#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4long double acoshl(long double x) {
5    return acosh(x);
6}
7#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
8/* acosh(x) = log(x + sqrt(x*x-1)) */
9long double acoshl(long double x) {
10    union ldshape u = {x};
11    int e = u.i.se & 0x7fff;
12
13    if (e < 0x3fff + 1) /* |x| < 2, invalid if x < 1 or nan */
14        return log1pl(x - 1 + sqrtl((x - 1) * (x - 1) + 2 * (x - 1)));
15    if (e < 0x3fff + 32) /* |x| < 0x1p32 */
16        return logl(2 * x - 1 / (x + sqrtl(x * x - 1)));
17    return logl(x) + 0.693147180559945309417232121458176568L;
18}
19#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
20// TODO: broken implementation to make things compile
21long double acoshl(long double x) {
22    return acosh(x);
23}
24#endif
25