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 * ====================================================
15 #include <sys/cdefs.h>
17 * See e_acosh.c for complete comments.
19 * Converted to long double by David Schultz <das@FreeBSD.ORG> and
30 #include "math_private.h"
32 /* EXP_LARGE is the threshold above which we use acosh(x) ~= log(2x). */
33 #if LDBL_MANT_DIG == 64
35 #elif LDBL_MANT_DIG == 113
38 #error "Unsupported long double format"
41 #if LDBL_MAX_EXP != 0x4000
42 /* We also require the usual expsign encoding. */
43 #error "Unsupported long double format"
46 #define BIAS (LDBL_MAX_EXP - 1)
51 #if LDBL_MANT_DIG == 64
52 static const union IEEEl2bits
53 u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
55 #elif LDBL_MANT_DIG == 113
56 static const long double
57 ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */
59 #error "Unsupported long double format"
69 GET_LDBL_EXPSIGN(hx, x);
70 if (hx < 0x3fff) { /* x < 1, or misnormal */
72 } else if (hx >= BIAS + EXP_LARGE) { /* x >= LARGE */
73 if (hx >= 0x7fff) { /* x is inf, NaN or misnormal */
76 RETURNI(logl(x)+ln2); /* acosh(huge)=log(2x), or misnormal */
77 } else if (hx == 0x3fff && x == 1) {
78 RETURNI(0.0); /* acosh(1) = 0 */
79 } else if (hx >= 0x4000) { /* LARGE > x >= 2, or misnormal */
81 RETURNI(logl(2.0*x-one/(x+sqrtl(t-one))));
84 RETURNI(log1pl(t+sqrtl(2.0*t+t*t)));