1 /* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */
3 /* @(#)e_acosh.c 1.3 95/01/18 */
5 * ====================================================
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 * Developed at SunSoft, a Sun Microsystems, Inc. business.
9 * Permission to use, copy, modify, and distribute this
10 * software is freely granted, provided that this notice
12 * ====================================================
16 #include <sys/cdefs.h>
17 __FBSDID("$FreeBSD$");
20 * See e_acosh.c for complete comments.
22 * Converted to long double by David Schultz <das@FreeBSD.ORG> and
33 #include "math_private.h"
35 /* EXP_LARGE is the threshold above which we use acosh(x) ~= log(2x). */
36 #if LDBL_MANT_DIG == 64
38 #elif LDBL_MANT_DIG == 113
41 #error "Unsupported long double format"
44 #if LDBL_MAX_EXP != 0x4000
45 /* We also require the usual expsign encoding. */
46 #error "Unsupported long double format"
49 #define BIAS (LDBL_MAX_EXP - 1)
54 #if LDBL_MANT_DIG == 64
55 static const union IEEEl2bits
56 u_ln2
= LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
58 #elif LDBL_MANT_DIG == 113
59 static const long double
60 ln2
= 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */
62 #error "Unsupported long double format"
72 GET_LDBL_EXPSIGN(hx
, x
);
73 if (hx
< 0x3fff) { /* x < 1, or misnormal */
75 } else if (hx
>= BIAS
+ EXP_LARGE
) { /* x >= LARGE */
76 if (hx
>= 0x7fff) { /* x is inf, NaN or misnormal */
79 RETURNI(logl(x
)+ln2
); /* acosh(huge)=log(2x), or misnormal */
80 } else if (hx
== 0x3fff && x
== 1) {
81 RETURNI(0.0); /* acosh(1) = 0 */
82 } else if (hx
>= 0x4000) { /* LARGE > x >= 2, or misnormal */
84 RETURNI(logl(2.0*x
-one
/(x
+sqrtl(t
-one
))));
87 RETURNI(log1pl(t
+sqrtl(2.0*t
+t
*t
)));