chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / sysdeps / ieee754 / ldbl-128 / e_acoshl.c
1 /* e_acoshl.c -- long double version of e_acosh.c.
2  * Conversion to long double by Jakub Jelinek, jj@ultra.linux.cz.
3  */
4
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  */
15
16 /* __ieee754_acoshl(x)
17  * Method :
18  *      Based on
19  *              acoshl(x) = logl [ x + sqrtl(x*x-1) ]
20  *      we have
21  *              acoshl(x) := logl(x)+ln2,       if x is large; else
22  *              acoshl(x) := logl(2x-1/(sqrtl(x*x-1)+x)) if x>2; else
23  *              acoshl(x) := log1pl(t+sqrtl(2.0*t+t*t)); where t=x-1.
24  *
25  * Special cases:
26  *      acoshl(x) is NaN with signal if x<1.
27  *      acoshl(NaN) is NaN without signal.
28  */
29
30 #include "math.h"
31 #include "math_private.h"
32
33 #ifdef __STDC__
34 static const long double
35 #else
36 static long double
37 #endif
38 one     = 1.0,
39 ln2     = 0.6931471805599453094172321214581766L;
40
41 #ifdef __STDC__
42         long double __ieee754_acoshl(long double x)
43 #else
44         long double __ieee754_acoshl(x)
45         long double x;
46 #endif
47 {
48         long double t;
49         u_int64_t lx;
50         int64_t hx;
51         GET_LDOUBLE_WORDS64(hx,lx,x);
52         if(hx<0x3fff000000000000LL) {           /* x < 1 */
53             return (x-x)/(x-x);
54         } else if(hx >=0x4035000000000000LL) {  /* x > 2**54 */
55             if(hx >=0x7fff000000000000LL) {     /* x is inf of NaN */
56                 return x+x;
57             } else
58                 return __ieee754_logl(x)+ln2;   /* acoshl(huge)=logl(2x) */
59         } else if(((hx-0x3fff000000000000LL)|lx)==0) {
60             return 0.0L;                        /* acosh(1) = 0 */
61         } else if (hx > 0x4000000000000000LL) { /* 2**28 > x > 2 */
62             t=x*x;
63             return __ieee754_logl(2.0L*x-one/(x+__ieee754_sqrtl(t-one)));
64         } else {                        /* 1<x<2 */
65             t = x-one;
66             return __log1pl(t+__sqrtl(2.0L*t+t*t));
67         }
68 }