1 /* e_acoshl.c -- long double version of e_acosh.c.
2  */
3 
4 /*
5  * ====================================================
6  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7  *
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
11  * is preserved.
12  * ====================================================
13  */
14 
15 /* __ieee754_acoshl(x)
16  * Method :
17  *	Based on
18  *		acoshl(x) = logl [ x + sqrtl(x*x-1) ]
19  *	we have
20  *		acoshl(x) := logl(x)+ln2,	if x is large; else
21  *		acoshl(x) := logl(2x-1/(sqrtl(x*x-1)+x)) if x>2; else
22  *		acoshl(x) := log1pl(t+sqrtl(2.0*t+t*t)); where t=x-1.
23  *
24  * Special cases:
25  *	acoshl(x) is NaN with signal if x<1.
26  *	acoshl(NaN) is NaN without signal.
27  */
28 
29 #include <math.h>
30 #include <math_private.h>
31 #include <libm-alias-finite.h>
32 
33 static const long double
34 one	= 1.0,
35 ln2	= 6.931471805599453094287e-01L; /* 0x3FFE, 0xB17217F7, 0xD1CF79AC */
36 
37 long double
__ieee754_acoshl(long double x)38 __ieee754_acoshl(long double x)
39 {
40 	long double t;
41 	uint32_t se,i0,i1;
42 	GET_LDOUBLE_WORDS(se,i0,i1,x);
43 	if(se<0x3fff || se & 0x8000) {	/* x < 1 */
44 	    return (x-x)/(x-x);
45 	} else if(se >=0x401d) {	/* x > 2**30 */
46 	    if(se >=0x7fff) {		/* x is inf of NaN */
47 		return x+x;
48 	    } else
49 		return __ieee754_logl(x)+ln2;	/* acoshl(huge)=logl(2x) */
50 	} else if(((se-0x3fff)|(i0^0x80000000)|i1)==0) {
51 	    return 0.0;			/* acosh(1) = 0 */
52 	} else if (se > 0x4000) {	/* 2**28 > x > 2 */
53 	    t=x*x;
54 	    return __ieee754_logl(2.0*x-one/(x+sqrtl(t-one)));
55 	} else {			/* 1<x<2 */
56 	    t = x-one;
57 	    return __log1pl(t+sqrtl(2.0*t+t*t));
58 	}
59 }
60 libm_alias_finite (__ieee754_acoshl, __acoshl)
61