xref: /openbsd-src/lib/libm/src/ld80/e_acoshl.c (revision 49393c004c040ee201e6408db68882c3fe4cb110)
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	= 6.931471805599453094287e-01L; /* 0x3FFE, 0xB17217F7, 0xD1CF79AC */
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_int32_t se,i0,i1;
40*49393c00Smartynas 	GET_LDOUBLE_WORDS(se,i0,i1,x);
41*49393c00Smartynas 	if(se<0x3fff || se & 0x8000) {	/* x < 1 */
42*49393c00Smartynas 	    return (x-x)/(x-x);
43*49393c00Smartynas 	} else if(se >=0x401d) {	/* x > 2**30 */
44*49393c00Smartynas 	    if(se >=0x7fff) {		/* x is inf of NaN */
45*49393c00Smartynas 		return x+x;
46*49393c00Smartynas 	    } else
47*49393c00Smartynas 		return logl(x)+ln2;	/* acoshl(huge)=logl(2x) */
48*49393c00Smartynas 	} else if(((se-0x3fff)|i0|i1)==0) {
49*49393c00Smartynas 	    return 0.0;			/* acosh(1) = 0 */
50*49393c00Smartynas 	} else if (se > 0x4000) {	/* 2**28 > x > 2 */
51*49393c00Smartynas 	    t=x*x;
52*49393c00Smartynas 	    return logl(2.0*x-one/(x+sqrtl(t-one)));
53*49393c00Smartynas 	} else {			/* 1<x<2 */
54*49393c00Smartynas 	    t = x-one;
55*49393c00Smartynas 	    return log1pl(t+sqrtl(2.0*t+t*t));
56*49393c00Smartynas 	}
57*49393c00Smartynas }
58