1 /* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */
3 /* @(#)s_asinh.c 5.1 93/09/24 */
5 * ====================================================
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 * Developed at SunPro, a Sun Microsystems, Inc. business.
9 * Permission to use, copy, modify, and distribute this
10 * software is freely granted, provided that this notice
12 * ====================================================
15 #include <sys/cdefs.h>
16 __FBSDID("$FreeBSD$");
19 * See s_asinh.c for complete comments.
21 * Converted to long double by David Schultz <das@FreeBSD.ORG> and
32 #include "math_private.h"
34 /* EXP_LARGE is the threshold above which we use asinh(x) ~= log(2x). */
35 /* EXP_TINY is the threshold below which we use asinh(x) ~= x. */
36 #if LDBL_MANT_DIG == 64
39 #elif LDBL_MANT_DIG == 113
43 #error "Unsupported long double format"
46 #if LDBL_MAX_EXP != 0x4000
47 /* We also require the usual expsign encoding. */
48 #error "Unsupported long double format"
51 #define BIAS (LDBL_MAX_EXP - 1)
54 one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
55 huge= 1.00000000000000000000e+300;
57 #if LDBL_MANT_DIG == 64
58 static const union IEEEl2bits
59 u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
61 #elif LDBL_MANT_DIG == 113
62 static const long double
63 ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */
65 #error "Unsupported long double format"
75 GET_LDBL_EXPSIGN(hx, x);
77 if (ix >= 0x7fff) RETURNI(x+x); /* x is inf, NaN or misnormal */
78 if (ix < BIAS + EXP_TINY) { /* |x| < TINY, or misnormal */
79 if (huge + x > one) RETURNI(x); /* return x inexact except 0 */
81 if (ix >= BIAS + EXP_LARGE) { /* |x| >= LARGE, or misnormal */
82 w = logl(fabsl(x))+ln2;
83 } else if (ix >= 0x4000) { /* LARGE > |x| >= 2.0, or misnormal */
85 w = logl(2.0*t+one/(sqrtl(x*x+one)+t));
86 } else { /* 2.0 > |x| >= TINY, or misnormal */
88 w =log1pl(fabsl(x)+t/(one+sqrtl(one+t)));
90 RETURNI((hx & 0x8000) == 0 ? w : -w);