s_asinh.c revision 21673
1193326Sed/* @(#)s_asinh.c 5.1 93/09/24 */
2193326Sed/*
3193326Sed * ====================================================
4193326Sed * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5193326Sed *
6193326Sed * Developed at SunPro, a Sun Microsystems, Inc. business.
7193326Sed * Permission to use, copy, modify, and distribute this
8193326Sed * software is freely granted, provided that this notice
9193326Sed * is preserved.
10193326Sed * ====================================================
11193326Sed */
12193326Sed
13193326Sed#ifndef lint
14193326Sedstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_asinh.c 21673 1997-01-14 07:20:47Z jkh $";
15193326Sed#endif
16193326Sed
17226633Sdim/* asinh(x)
18193326Sed * Method :
19263508Sdim *	Based on
20193326Sed *		asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
21193326Sed *	we have
22193326Sed *	asinh(x) := x  if  1+x*x=1,
23193326Sed *		 := sign(x)*(log(x)+ln2)) for large |x|, else
24193326Sed *		 := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
25193326Sed *		 := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
26234353Sdim */
27234353Sdim
28193326Sed#include "math.h"
29239462Sdim#include "math_private.h"
30193326Sed
31193326Sed#ifdef __STDC__
32193326Sedstatic const double
33193326Sed#else
34193326Sedstatic double
35193326Sed#endif
36193326Sedone =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
37193326Sedln2 =  6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
38193326Sedhuge=  1.00000000000000000000e+300;
39193326Sed
40193326Sed#ifdef __STDC__
41193326Sed	double asinh(double x)
42193326Sed#else
43193326Sed	double asinh(x)
44198092Srdivacky	double x;
45193326Sed#endif
46193326Sed{
47193326Sed	double t,w;
48193326Sed	int32_t hx,ix;
49198092Srdivacky	GET_HIGH_WORD(hx,x);
50193326Sed	ix = hx&0x7fffffff;
51193326Sed	if(ix>=0x7ff00000) return x+x;	/* x is inf or NaN */
52193326Sed	if(ix< 0x3e300000) {	/* |x|<2**-28 */
53198092Srdivacky	    if(huge+x>one) return x;	/* return x inexact except 0 */
54193326Sed	}
55193326Sed	if(ix>0x41b00000) {	/* |x| > 2**28 */
56193326Sed	    w = __ieee754_log(fabs(x))+ln2;
57226633Sdim	} else if (ix>0x40000000) {	/* 2**28 > |x| > 2.0 */
58226633Sdim	    t = fabs(x);
59226633Sdim	    w = __ieee754_log(2.0*t+one/(sqrt(x*x+one)+t));
60249423Sdim	} else {		/* 2.0 > |x| > 2**-28 */
61249423Sdim	    t = x*x;
62249423Sdim	    w =log1p(fabs(x)+t/(one+sqrt(one+t)));
63249423Sdim	}
64226633Sdim	if(hx>0) return w; else return -w;
65193326Sed}
66193326Sed