| 1/* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */
|
1 2/* @(#)e_acosh.c 1.3 95/01/18 */ 3/* 4 * ==================================================== 5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 * 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 10 * is preserved. 11 * ==================================================== 12 * 13 */ 14 15#include <sys/cdefs.h>
| 2 3/* @(#)e_acosh.c 1.3 95/01/18 */ 4/* 5 * ==================================================== 6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 7 * 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 11 * is preserved. 12 * ==================================================== 13 * 14 */ 15 16#include <sys/cdefs.h>
|
16__FBSDID("$FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das $");
| 17__FBSDID("$FreeBSD: head/lib/msun/src/e_acoshl.c 251599 2013-06-10 06:04:58Z das $");
|
17
| 18
|
18/* __ieee754_acosh(x) 19 * Method : 20 * Based on 21 * acosh(x) = log [ x + sqrt(x*x-1) ] 22 * we have 23 * acosh(x) := log(x)+ln2, if x is large; else 24 * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else 25 * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
| 19/* 20 * See e_acosh.c for complete comments.
|
26 *
| 21 *
|
27 * Special cases: 28 * acosh(x) is NaN with signal if x<1. 29 * acosh(NaN) is NaN without signal.
| 22 * Converted to long double by David Schultz <das@FreeBSD.ORG> and 23 * Bruce D. Evans.
|
30 */ 31
| 24 */ 25
|
| 26#include <float.h> 27#ifdef __i386__ 28#include <ieeefp.h> 29#endif 30 31#include "fpmath.h"
|
32#include "math.h" 33#include "math_private.h" 34
| 32#include "math.h" 33#include "math_private.h" 34
|
| 35/* EXP_LARGE is the threshold above which we use acosh(x) ~= log(2x). */ 36#if LDBL_MANT_DIG == 64 37#define EXP_LARGE 34 38#elif LDBL_MANT_DIG == 113 39#define EXP_LARGE 58 40#else 41#error "Unsupported long double format" 42#endif 43 44#if LDBL_MAX_EXP != 0x4000 45/* We also require the usual expsign encoding. */ 46#error "Unsupported long double format" 47#endif 48 49#define BIAS (LDBL_MAX_EXP - 1) 50
|
35static const double
| 51static const double
|
36one = 1.0, 37ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
| 52one = 1.0;
|
38
| 53
|
39double 40__ieee754_acosh(double x)
| 54#if LDBL_MANT_DIG == 64 55static const union IEEEl2bits 56u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L); 57#define ln2 u_ln2.e 58#elif LDBL_MANT_DIG == 113 59static const long double 60ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */ 61#else 62#error "Unsupported long double format" 63#endif 64 65long double 66acoshl(long double x)
|
41{
| 67{
|
42 double t; 43 int32_t hx; 44 u_int32_t lx; 45 EXTRACT_WORDS(hx,lx,x); 46 if(hx<0x3ff00000) { /* x < 1 */ 47 return (x-x)/(x-x); 48 } else if(hx >=0x41b00000) { /* x > 2**28 */ 49 if(hx >=0x7ff00000) { /* x is inf of NaN */ 50 return x+x;
| 68 long double t; 69 int16_t hx; 70 71 ENTERI(); 72 GET_LDBL_EXPSIGN(hx, x); 73 if (hx < 0x3fff) { /* x < 1, or misnormal */ 74 RETURNI((x-x)/(x-x)); 75 } else if (hx >= BIAS + EXP_LARGE) { /* x >= LARGE */ 76 if (hx >= 0x7fff) { /* x is inf, NaN or misnormal */ 77 RETURNI(x+x);
|
51 } else
| 78 } else
|
52 return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */ 53 } else if(((hx-0x3ff00000)|lx)==0) { 54 return 0.0; /* acosh(1) = 0 */ 55 } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
| 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 */
|
56 t=x*x;
| 83 t=x*x;
|
57 return __ieee754_log(2.0*x-one/(x+sqrt(t-one)));
| 84 RETURNI(logl(2.0*x-one/(x+sqrtl(t-one))));
|
58 } else { /* 1<x<2 */ 59 t = x-one;
| 85 } else { /* 1<x<2 */ 86 t = x-one;
|
60 return log1p(t+sqrt(2.0*t+t*t));
| 87 RETURNI(log1pl(t+sqrtl(2.0*t+t*t)));
|
61 } 62}
| 88 } 89}
|