#include <float.h>
#ifdef __i386__
#include <ieeefp.h>
#endif
#include "fpmath.h"
#include "math.h"
#include "math_private.h"
#if LDBL_MANT_DIG == 64
#define EXP_LARGE 34
#elif LDBL_MANT_DIG == 113
#define EXP_LARGE 58
#else
#error "Unsupported long double format"
#endif
#if LDBL_MAX_EXP != 0x4000
#error "Unsupported long double format"
#endif
#define BIAS (LDBL_MAX_EXP - 1)
static const double
one = 1.0;
#if LDBL_MANT_DIG == 64
static const union IEEEl2bits
u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
#define ln2 u_ln2.e
#elif LDBL_MANT_DIG == 113
static const long double
ln2 = 6.93147180559945309417232121458176568e-1L;
#else
#error "Unsupported long double format"
#endif
long double
acoshl(long double x)
{
long double t;
int16_t hx;
ENTERI();
GET_LDBL_EXPSIGN(hx, x);
if (hx < 0x3fff) {
RETURNI((x-x)/(x-x));
} else if (hx >= BIAS + EXP_LARGE) {
if (hx >= 0x7fff) {
RETURNI(x+x);
} else
RETURNI(logl(x)+ln2);
} else if (hx == 0x3fff && x == 1) {
RETURNI(0.0);
} else if (hx >= 0x4000) {
t=x*x;
RETURNI(logl(2.0*x-one/(x+sqrtl(t-one))));
} else {
t = x-one;
RETURNI(log1pl(t+sqrtl(2.0*t+t*t)));
}
}