13f708241SDavid Schultz
23a8617a8SJordan K. Hubbard /*
33a8617a8SJordan K. Hubbard * ====================================================
43a8617a8SJordan K. Hubbard * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
53a8617a8SJordan K. Hubbard *
63f708241SDavid Schultz * Developed at SunSoft, a Sun Microsystems, Inc. business.
73a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this
83a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice
93a8617a8SJordan K. Hubbard * is preserved.
103a8617a8SJordan K. Hubbard * ====================================================
113f708241SDavid Schultz *
123a8617a8SJordan K. Hubbard */
133a8617a8SJordan K. Hubbard
14*99843eb8SSteve Kargl /* acosh(x)
153a8617a8SJordan K. Hubbard * Method :
163a8617a8SJordan K. Hubbard * Based on
173a8617a8SJordan K. Hubbard * acosh(x) = log [ x + sqrt(x*x-1) ]
183a8617a8SJordan K. Hubbard * we have
193a8617a8SJordan K. Hubbard * acosh(x) := log(x)+ln2, if x is large; else
203a8617a8SJordan K. Hubbard * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
213a8617a8SJordan K. Hubbard * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
223a8617a8SJordan K. Hubbard *
233a8617a8SJordan K. Hubbard * Special cases:
243a8617a8SJordan K. Hubbard * acosh(x) is NaN with signal if x<1.
253a8617a8SJordan K. Hubbard * acosh(NaN) is NaN without signal.
263a8617a8SJordan K. Hubbard */
273a8617a8SJordan K. Hubbard
28998b640bSDavid Schultz #include <float.h>
29998b640bSDavid Schultz
303a8617a8SJordan K. Hubbard #include "math.h"
313a8617a8SJordan K. Hubbard #include "math_private.h"
323a8617a8SJordan K. Hubbard
333a8617a8SJordan K. Hubbard static const double
343a8617a8SJordan K. Hubbard one = 1.0,
353a8617a8SJordan K. Hubbard ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
363a8617a8SJordan K. Hubbard
37a82bbc73SAlfred Perlstein double
acosh(double x)38*99843eb8SSteve Kargl acosh(double x)
393a8617a8SJordan K. Hubbard {
403a8617a8SJordan K. Hubbard double t;
413a8617a8SJordan K. Hubbard int32_t hx;
423a8617a8SJordan K. Hubbard u_int32_t lx;
433a8617a8SJordan K. Hubbard EXTRACT_WORDS(hx,lx,x);
443a8617a8SJordan K. Hubbard if(hx<0x3ff00000) { /* x < 1 */
453a8617a8SJordan K. Hubbard return (x-x)/(x-x);
463a8617a8SJordan K. Hubbard } else if(hx >=0x41b00000) { /* x > 2**28 */
473a8617a8SJordan K. Hubbard if(hx >=0x7ff00000) { /* x is inf of NaN */
483a8617a8SJordan K. Hubbard return x+x;
493a8617a8SJordan K. Hubbard } else
50*99843eb8SSteve Kargl return log(x)+ln2; /* acosh(huge)=log(2x) */
513a8617a8SJordan K. Hubbard } else if(((hx-0x3ff00000)|lx)==0) {
523a8617a8SJordan K. Hubbard return 0.0; /* acosh(1) = 0 */
533a8617a8SJordan K. Hubbard } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
543a8617a8SJordan K. Hubbard t=x*x;
55*99843eb8SSteve Kargl return log(2.0*x-one/(x+sqrt(t-one)));
563a8617a8SJordan K. Hubbard } else { /* 1<x<2 */
573a8617a8SJordan K. Hubbard t = x-one;
583f708241SDavid Schultz return log1p(t+sqrt(2.0*t+t*t));
593a8617a8SJordan K. Hubbard }
603a8617a8SJordan K. Hubbard }
61998b640bSDavid Schultz
62998b640bSDavid Schultz #if LDBL_MANT_DIG == 53
63998b640bSDavid Schultz __weak_reference(acosh, acoshl);
64998b640bSDavid Schultz #endif
65