1 /* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunSoft, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
16 * See e_acosh.c for complete comments.
18 * Converted to long double by David Schultz <das@FreeBSD.ORG> and
29 #include "math_private.h"
31 /* EXP_LARGE is the threshold above which we use acosh(x) ~= log(2x). */
32 #if LDBL_MANT_DIG == 64
34 #elif LDBL_MANT_DIG == 113
37 #error "Unsupported long double format"
40 #if LDBL_MAX_EXP != 0x4000
41 /* We also require the usual expsign encoding. */
42 #error "Unsupported long double format"
45 #define BIAS (LDBL_MAX_EXP - 1)
50 #if LDBL_MANT_DIG == 64
51 static const union IEEEl2bits
52 u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
54 #elif LDBL_MANT_DIG == 113
55 static const long double
56 ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */
58 #error "Unsupported long double format"
68 GET_LDBL_EXPSIGN(hx, x);
69 if (hx < 0x3fff) { /* x < 1, or misnormal */
71 } else if (hx >= BIAS + EXP_LARGE) { /* x >= LARGE */
72 if (hx >= 0x7fff) { /* x is inf, NaN or misnormal */
75 RETURNI(logl(x)+ln2); /* acosh(huge)=log(2x), or misnormal */
76 } else if (hx == 0x3fff && x == 1) {
77 RETURNI(0.0); /* acosh(1) = 0 */
78 } else if (hx >= 0x4000) { /* LARGE > x >= 2, or misnormal */
80 RETURNI(logl(2.0*x-one/(x+sqrtl(t-one))));
83 RETURNI(log1pl(t+sqrtl(2.0*t+t*t)));