xref: /csrg-svn/lib/libm/common_source/asinh.c (revision 61283)
134124Sbostic /*
2*61283Sbostic  * Copyright (c) 1985, 1993
3*61283Sbostic  *	The Regents of the University of California.  All rights reserved.
434124Sbostic  *
542655Sbostic  * %sccs.include.redist.c%
624588Szliu  */
724588Szliu 
824588Szliu #ifndef lint
9*61283Sbostic static char sccsid[] = "@(#)asinh.c	8.1 (Berkeley) 06/04/93";
1034124Sbostic #endif /* not lint */
1124588Szliu 
1224588Szliu /* ASINH(X)
1324588Szliu  * RETURN THE INVERSE HYPERBOLIC SINE OF X
1424588Szliu  * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS)
1524588Szliu  * CODED IN C BY K.C. NG, 2/16/85;
1624588Szliu  * REVISED BY K.C. NG on 3/7/85, 3/24/85, 4/16/85.
1724588Szliu  *
1824588Szliu  * Required system supported functions :
1924588Szliu  *	copysign(x,y)
2024588Szliu  *	sqrt(x)
2124588Szliu  *
2224588Szliu  * Required kernel function:
2324588Szliu  *	log1p(x) 		...return log(1+x)
2424588Szliu  *
2524588Szliu  * Method :
2624588Szliu  *	Based on
2724588Szliu  *		asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
2824588Szliu  *	we have
2924588Szliu  *	asinh(x) := x  if  1+x*x=1,
3024588Szliu  *		 := sign(x)*(log1p(x)+ln2))	 if sqrt(1+x*x)=x, else
3124588Szliu  *		 := sign(x)*log1p(|x| + |x|/(1/|x| + sqrt(1+(1/|x|)^2)) )
3224588Szliu  *
3324588Szliu  * Accuracy:
3424588Szliu  *	asinh(x) returns the exact inverse hyperbolic sine of x nearly rounded.
3524588Szliu  *	In a test run with 52,000 random arguments on a VAX, the maximum
3624588Szliu  *	observed error was 1.58 ulps (units in the last place).
3724588Szliu  *
3824588Szliu  * Constants:
3924588Szliu  * The hexadecimal values are the intended ones for the following constants.
4024588Szliu  * The decimal values may be used, provided that the compiler will convert
4124588Szliu  * from decimal to binary accurately enough to produce the hexadecimal values
4224588Szliu  * shown.
4324588Szliu  */
4435679Sbostic #include "mathimpl.h"
4524588Szliu 
4635679Sbostic vc(ln2hi, 6.9314718055829871446E-1  ,7217,4031,0000,f7d0,   0, .B17217F7D00000)
4735679Sbostic vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC)
4824588Szliu 
4935679Sbostic ic(ln2hi, 6.9314718036912381649E-1,   -1, 1.62E42FEE00000)
5035679Sbostic ic(ln2lo, 1.9082149292705877000E-10, -33, 1.A39EF35793C76)
5135679Sbostic 
5235679Sbostic #ifdef vccast
5335679Sbostic #define    ln2hi    vccast(ln2hi)
5435679Sbostic #define    ln2lo    vccast(ln2lo)
5535679Sbostic #endif
5635679Sbostic 
5724588Szliu double asinh(x)
5824588Szliu double x;
5924588Szliu {
6035679Sbostic 	double t,s;
6135679Sbostic 	const static double	small=1.0E-10,	/* fl(1+small*small) == 1 */
6235679Sbostic 				big  =1.0E20,	/* fl(1+big) == big */
6335679Sbostic 				one  =1.0   ;
6424588Szliu 
6531853Szliu #if !defined(vax)&&!defined(tahoe)
6624588Szliu 	if(x!=x) return(x);	/* x is NaN */
6731853Szliu #endif	/* !defined(vax)&&!defined(tahoe) */
6824588Szliu 	if((t=copysign(x,one))>small)
6924588Szliu 	    if(t<big) {
7024588Szliu 	     	s=one/t; return(copysign(log1p(t+t/(s+sqrt(one+s*s))),x)); }
7124588Szliu 	    else	/* if |x| > big */
7224588Szliu 		{s=log1p(t)+ln2lo; return(copysign(s+ln2hi,x));}
7324588Szliu 	else	/* if |x| < small */
7424588Szliu 	    return(x);
7524588Szliu }
76