1*2fe8fb19SBen Gras /* @(#)e_acosh.c 5.1 93/09/24 */
2*2fe8fb19SBen Gras /*
3*2fe8fb19SBen Gras * ====================================================
4*2fe8fb19SBen Gras * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5*2fe8fb19SBen Gras *
6*2fe8fb19SBen Gras * Developed at SunPro, a Sun Microsystems, Inc. business.
7*2fe8fb19SBen Gras * Permission to use, copy, modify, and distribute this
8*2fe8fb19SBen Gras * software is freely granted, provided that this notice
9*2fe8fb19SBen Gras * is preserved.
10*2fe8fb19SBen Gras * ====================================================
11*2fe8fb19SBen Gras */
12*2fe8fb19SBen Gras
13*2fe8fb19SBen Gras #include <sys/cdefs.h>
14*2fe8fb19SBen Gras #if defined(LIBM_SCCS) && !defined(lint)
15*2fe8fb19SBen Gras __RCSID("$NetBSD: e_acosh.c,v 1.12 2002/05/26 22:01:48 wiz Exp $");
16*2fe8fb19SBen Gras #endif
17*2fe8fb19SBen Gras
18*2fe8fb19SBen Gras /* __ieee754_acosh(x)
19*2fe8fb19SBen Gras * Method :
20*2fe8fb19SBen Gras * Based on
21*2fe8fb19SBen Gras * acosh(x) = log [ x + sqrt(x*x-1) ]
22*2fe8fb19SBen Gras * we have
23*2fe8fb19SBen Gras * acosh(x) := log(x)+ln2, if x is large; else
24*2fe8fb19SBen Gras * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
25*2fe8fb19SBen Gras * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
26*2fe8fb19SBen Gras *
27*2fe8fb19SBen Gras * Special cases:
28*2fe8fb19SBen Gras * acosh(x) is NaN with signal if x<1.
29*2fe8fb19SBen Gras * acosh(NaN) is NaN without signal.
30*2fe8fb19SBen Gras */
31*2fe8fb19SBen Gras
32*2fe8fb19SBen Gras #include "math.h"
33*2fe8fb19SBen Gras #include "math_private.h"
34*2fe8fb19SBen Gras
35*2fe8fb19SBen Gras static const double
36*2fe8fb19SBen Gras one = 1.0,
37*2fe8fb19SBen Gras ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
38*2fe8fb19SBen Gras
39*2fe8fb19SBen Gras double
__ieee754_acosh(double x)40*2fe8fb19SBen Gras __ieee754_acosh(double x)
41*2fe8fb19SBen Gras {
42*2fe8fb19SBen Gras double t;
43*2fe8fb19SBen Gras int32_t hx;
44*2fe8fb19SBen Gras u_int32_t lx;
45*2fe8fb19SBen Gras EXTRACT_WORDS(hx,lx,x);
46*2fe8fb19SBen Gras if(hx<0x3ff00000) { /* x < 1 */
47*2fe8fb19SBen Gras return (x-x)/(x-x);
48*2fe8fb19SBen Gras } else if(hx >=0x41b00000) { /* x > 2**28 */
49*2fe8fb19SBen Gras if(hx >=0x7ff00000) { /* x is inf of NaN */
50*2fe8fb19SBen Gras return x+x;
51*2fe8fb19SBen Gras } else
52*2fe8fb19SBen Gras return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
53*2fe8fb19SBen Gras } else if(((hx-0x3ff00000)|lx)==0) {
54*2fe8fb19SBen Gras return 0.0; /* acosh(1) = 0 */
55*2fe8fb19SBen Gras } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
56*2fe8fb19SBen Gras t=x*x;
57*2fe8fb19SBen Gras return __ieee754_log(2.0*x-one/(x+__ieee754_sqrt(t-one)));
58*2fe8fb19SBen Gras } else { /* 1<x<2 */
59*2fe8fb19SBen Gras t = x-one;
60*2fe8fb19SBen Gras return log1p(t+sqrt(2.0*t+t*t));
61*2fe8fb19SBen Gras }
62*2fe8fb19SBen Gras }
63