1*49393c00Smartynas /* @(#)e_acosh.c 5.1 93/09/24 */
2*49393c00Smartynas /*
3*49393c00Smartynas * ====================================================
4*49393c00Smartynas * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5*49393c00Smartynas *
6*49393c00Smartynas * Developed at SunPro, a Sun Microsystems, Inc. business.
7*49393c00Smartynas * Permission to use, copy, modify, and distribute this
8*49393c00Smartynas * software is freely granted, provided that this notice
9*49393c00Smartynas * is preserved.
10*49393c00Smartynas * ====================================================
11*49393c00Smartynas */
12*49393c00Smartynas
13*49393c00Smartynas /* acoshl(x)
14*49393c00Smartynas * Method :
15*49393c00Smartynas * Based on
16*49393c00Smartynas * acoshl(x) = logl [ x + sqrtl(x*x-1) ]
17*49393c00Smartynas * we have
18*49393c00Smartynas * acoshl(x) := logl(x)+ln2, if x is large; else
19*49393c00Smartynas * acoshl(x) := logl(2x-1/(sqrtl(x*x-1)+x)) if x>2; else
20*49393c00Smartynas * acoshl(x) := log1pl(t+sqrtl(2.0*t+t*t)); where t=x-1.
21*49393c00Smartynas *
22*49393c00Smartynas * Special cases:
23*49393c00Smartynas * acoshl(x) is NaN with signal if x<1.
24*49393c00Smartynas * acoshl(NaN) is NaN without signal.
25*49393c00Smartynas */
26*49393c00Smartynas
27*49393c00Smartynas #include <math.h>
28*49393c00Smartynas
29*49393c00Smartynas #include "math_private.h"
30*49393c00Smartynas
31*49393c00Smartynas static const long double
32*49393c00Smartynas one = 1.0,
33*49393c00Smartynas ln2 = 0.6931471805599453094172321214581766L;
34*49393c00Smartynas
35*49393c00Smartynas long double
acoshl(long double x)36*49393c00Smartynas acoshl(long double x)
37*49393c00Smartynas {
38*49393c00Smartynas long double t;
39*49393c00Smartynas u_int64_t lx;
40*49393c00Smartynas int64_t hx;
41*49393c00Smartynas GET_LDOUBLE_WORDS64(hx,lx,x);
42*49393c00Smartynas if(hx<0x3fff000000000000LL) { /* x < 1 */
43*49393c00Smartynas return (x-x)/(x-x);
44*49393c00Smartynas } else if(hx >=0x4035000000000000LL) { /* x > 2**54 */
45*49393c00Smartynas if(hx >=0x7fff000000000000LL) { /* x is inf of NaN */
46*49393c00Smartynas return x+x;
47*49393c00Smartynas } else
48*49393c00Smartynas return logl(x)+ln2; /* acoshl(huge)=logl(2x) */
49*49393c00Smartynas } else if(((hx-0x3fff000000000000LL)|lx)==0) {
50*49393c00Smartynas return 0.0L; /* acosh(1) = 0 */
51*49393c00Smartynas } else if (hx > 0x4000000000000000LL) { /* 2**28 > x > 2 */
52*49393c00Smartynas t=x*x;
53*49393c00Smartynas return logl(2.0L*x-one/(x+sqrtl(t-one)));
54*49393c00Smartynas } else { /* 1<x<2 */
55*49393c00Smartynas t = x-one;
56*49393c00Smartynas return log1pl(t+sqrtl(2.0L*t+t*t));
57*49393c00Smartynas }
58*49393c00Smartynas }
59