1*2fe8fb19SBen Gras /* @(#)s_asinh.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: s_asinh.c,v 1.12 2002/05/26 22:01:54 wiz Exp $");
16*2fe8fb19SBen Gras #endif
17*2fe8fb19SBen Gras
18*2fe8fb19SBen Gras /* asinh(x)
19*2fe8fb19SBen Gras * Method :
20*2fe8fb19SBen Gras * Based on
21*2fe8fb19SBen Gras * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
22*2fe8fb19SBen Gras * we have
23*2fe8fb19SBen Gras * asinh(x) := x if 1+x*x=1,
24*2fe8fb19SBen Gras * := sign(x)*(log(x)+ln2)) for large |x|, else
25*2fe8fb19SBen Gras * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
26*2fe8fb19SBen Gras * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
27*2fe8fb19SBen Gras */
28*2fe8fb19SBen Gras
29*2fe8fb19SBen Gras #include "math.h"
30*2fe8fb19SBen Gras #include "math_private.h"
31*2fe8fb19SBen Gras
32*2fe8fb19SBen Gras static const double
33*2fe8fb19SBen Gras one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
34*2fe8fb19SBen Gras ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
35*2fe8fb19SBen Gras huge= 1.00000000000000000000e+300;
36*2fe8fb19SBen Gras
37*2fe8fb19SBen Gras double
asinh(double x)38*2fe8fb19SBen Gras asinh(double x)
39*2fe8fb19SBen Gras {
40*2fe8fb19SBen Gras double t,w;
41*2fe8fb19SBen Gras int32_t hx,ix;
42*2fe8fb19SBen Gras GET_HIGH_WORD(hx,x);
43*2fe8fb19SBen Gras ix = hx&0x7fffffff;
44*2fe8fb19SBen Gras if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
45*2fe8fb19SBen Gras if(ix< 0x3e300000) { /* |x|<2**-28 */
46*2fe8fb19SBen Gras if(huge+x>one) return x; /* return x inexact except 0 */
47*2fe8fb19SBen Gras }
48*2fe8fb19SBen Gras if(ix>0x41b00000) { /* |x| > 2**28 */
49*2fe8fb19SBen Gras w = __ieee754_log(fabs(x))+ln2;
50*2fe8fb19SBen Gras } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
51*2fe8fb19SBen Gras t = fabs(x);
52*2fe8fb19SBen Gras w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t));
53*2fe8fb19SBen Gras } else { /* 2.0 > |x| > 2**-28 */
54*2fe8fb19SBen Gras t = x*x;
55*2fe8fb19SBen Gras w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t)));
56*2fe8fb19SBen Gras }
57*2fe8fb19SBen Gras if(hx>0) return w; else return -w;
58*2fe8fb19SBen Gras }
59