xref: /netbsd-src/lib/libm/src/s_asinh.c (revision aa30599e066edca03ae9611c8115625435305425)
113618394Sjtc /* @(#)s_asinh.c 5.1 93/09/24 */
213618394Sjtc /*
313618394Sjtc  * ====================================================
413618394Sjtc  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
513618394Sjtc  *
613618394Sjtc  * Developed at SunPro, a Sun Microsystems, Inc. business.
713618394Sjtc  * Permission to use, copy, modify, and distribute this
813618394Sjtc  * software is freely granted, provided that this notice
913618394Sjtc  * is preserved.
1013618394Sjtc  * ====================================================
1113618394Sjtc  */
1213618394Sjtc 
13dd7adfbfSlukem #include <sys/cdefs.h>
14d1f06e0bSjtc #if defined(LIBM_SCCS) && !defined(lint)
15*aa30599eSwiz __RCSID("$NetBSD: s_asinh.c,v 1.12 2002/05/26 22:01:54 wiz Exp $");
16bc3f7bf6Sjtc #endif
17bc3f7bf6Sjtc 
1813618394Sjtc /* asinh(x)
1913618394Sjtc  * Method :
2013618394Sjtc  *	Based on
2113618394Sjtc  *		asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
2213618394Sjtc  *	we have
2313618394Sjtc  *	asinh(x) := x  if  1+x*x=1,
2413618394Sjtc  *		 := sign(x)*(log(x)+ln2)) for large |x|, else
2513618394Sjtc  *		 := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
2613618394Sjtc  *		 := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
2713618394Sjtc  */
2813618394Sjtc 
298346e333Sjtc #include "math.h"
308346e333Sjtc #include "math_private.h"
3113618394Sjtc 
3213618394Sjtc static const double
3313618394Sjtc one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
3413618394Sjtc ln2 =  6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
3513618394Sjtc huge=  1.00000000000000000000e+300;
3613618394Sjtc 
37*aa30599eSwiz double
asinh(double x)38*aa30599eSwiz asinh(double x)
3913618394Sjtc {
4013618394Sjtc 	double t,w;
41b0c9d092Sjtc 	int32_t hx,ix;
428346e333Sjtc 	GET_HIGH_WORD(hx,x);
4313618394Sjtc 	ix = hx&0x7fffffff;
4413618394Sjtc 	if(ix>=0x7ff00000) return x+x;	/* x is inf or NaN */
4513618394Sjtc 	if(ix< 0x3e300000) {	/* |x|<2**-28 */
4613618394Sjtc 	    if(huge+x>one) return x;	/* return x inexact except 0 */
4713618394Sjtc 	}
4813618394Sjtc 	if(ix>0x41b00000) {	/* |x| > 2**28 */
4913618394Sjtc 	    w = __ieee754_log(fabs(x))+ln2;
5013618394Sjtc 	} else if (ix>0x40000000) {	/* 2**28 > |x| > 2.0 */
5113618394Sjtc 	    t = fabs(x);
52c1c8f420Sjtc 	    w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t));
5313618394Sjtc 	} else {		/* 2.0 > |x| > 2**-28 */
5413618394Sjtc 	    t = x*x;
55c1c8f420Sjtc 	    w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t)));
5613618394Sjtc 	}
5713618394Sjtc 	if(hx>0) return w; else return -w;
5813618394Sjtc }
59