1 /* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */ 2 3 /* 4 * ==================================================== 5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 * 7 * Developed at SunPro, a Sun Microsystems, Inc. business. 8 * Permission to use, copy, modify, and distribute this 9 * software is freely granted, provided that this notice 10 * is preserved. 11 * ==================================================== 12 */ 13 14 #include <sys/cdefs.h> 15 16 #include "namespace.h" 17 18 #include <float.h> 19 #include <machine/ieee.h> 20 21 #include "math.h" 22 #include "math_private.h" 23 24 __weak_alias(asinhl, _asinhl) 25 26 #ifdef __HAVE_LONG_DOUBLE 27 28 /* 29 * See s_asinh.c for complete comments. 30 * 31 * Converted to long double by David Schultz <das@FreeBSD.ORG> and 32 * Bruce D. Evans. 33 */ 34 35 #ifdef __i386__ 36 #include <ieeefp.h> 37 #endif 38 39 /* EXP_LARGE is the threshold above which we use asinh(x) ~= log(2x). */ 40 /* EXP_TINY is the threshold below which we use asinh(x) ~= x. */ 41 #if LDBL_MANT_DIG == 64 42 #define EXP_LARGE 34 43 #define EXP_TINY -34 44 #elif LDBL_MANT_DIG == 113 45 #define EXP_LARGE 58 46 #define EXP_TINY -58 47 #else 48 #error "Unsupported long double format" 49 #endif 50 51 #if LDBL_MAX_EXP != 0x4000 52 /* We also require the usual expsign encoding. */ 53 #error "Unsupported long double format" 54 #endif 55 56 #define BIAS (LDBL_MAX_EXP - 1) 57 58 static const double 59 one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ 60 huge= 1.00000000000000000000e+300; 61 62 #if LDBL_MANT_DIG == 64 63 static const union ieee_ext_u 64 u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L); 65 #define ln2 u_ln2.extu_ld 66 #elif LDBL_MANT_DIG == 113 67 static const long double 68 ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */ 69 #else 70 #error "Unsupported long double format" 71 #endif 72 73 long double 74 asinhl(long double x) 75 { 76 long double t, w; 77 uint16_t hx, ix; 78 79 ENTERI(); 80 GET_LDBL_EXPSIGN(hx, x); 81 ix = hx & 0x7fff; 82 if (ix >= 0x7fff) RETURNI(x+x); /* x is inf, NaN or misnormal */ 83 if (ix < BIAS + EXP_TINY) { /* |x| < TINY, or misnormal */ 84 if (huge + x > one) RETURNI(x); /* return x inexact except 0 */ 85 } 86 if (ix >= BIAS + EXP_LARGE) { /* |x| >= LARGE, or misnormal */ 87 w = logl(fabsl(x))+ln2; 88 } else if (ix >= 0x4000) { /* LARGE > |x| >= 2.0, or misnormal */ 89 t = fabsl(x); 90 w = logl(2.0*t+one/(sqrtl(x*x+one)+t)); 91 } else { /* 2.0 > |x| >= TINY, or misnormal */ 92 t = x*x; 93 w =log1pl(fabsl(x)+t/(one+sqrtl(one+t))); 94 } 95 RETURNI((hx & 0x8000) == 0 ? w : -w); 96 } 97 #else 98 long double 99 asinhl(long double x) 100 { 101 return asinh(x); 102 } 103 #endif 104