s_asinh.c revision 2116
1240116Smarcel/* @(#)s_asinh.c 5.1 93/09/24 */ 2240116Smarcel/* 3240116Smarcel * ==================================================== 4240116Smarcel * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5240116Smarcel * 6240116Smarcel * Developed at SunPro, a Sun Microsystems, Inc. business. 7240116Smarcel * Permission to use, copy, modify, and distribute this 8240116Smarcel * software is freely granted, provided that this notice 9240116Smarcel * is preserved. 10240116Smarcel * ==================================================== 11240116Smarcel */ 12240116Smarcel 13240116Smarcel#ifndef lint 14240116Smarcelstatic char rcsid[] = "$Id: s_asinh.c,v 1.6 1994/08/18 23:06:20 jtc Exp $"; 15240116Smarcel#endif 16240116Smarcel 17240116Smarcel/* asinh(x) 18240116Smarcel * Method : 19240116Smarcel * Based on 20240116Smarcel * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 21240116Smarcel * we have 22240116Smarcel * asinh(x) := x if 1+x*x=1, 23240116Smarcel * := sign(x)*(log(x)+ln2)) for large |x|, else 24240116Smarcel * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else 25240116Smarcel * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) 26275988Sngie */ 27275988Sngie 28240116Smarcel#include "math.h" 29240116Smarcel#include "math_private.h" 30240116Smarcel 31240116Smarcel#ifdef __STDC__ 32240116Smarcelstatic const double 33240116Smarcel#else 34240116Smarcelstatic double 35240116Smarcel#endif 36240116Smarcelone = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ 37240116Smarcelln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ 38240116Smarcelhuge= 1.00000000000000000000e+300; 39240116Smarcel 40240116Smarcel#ifdef __STDC__ 41275988Sngie double asinh(double x) 42240116Smarcel#else 43240116Smarcel double asinh(x) 44240116Smarcel double x; 45240116Smarcel#endif 46240116Smarcel{ 47240116Smarcel double t,w; 48240116Smarcel int32_t hx,ix; 49240116Smarcel GET_HIGH_WORD(hx,x); 50240116Smarcel ix = hx&0x7fffffff; 51240116Smarcel if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */ 52240116Smarcel if(ix< 0x3e300000) { /* |x|<2**-28 */ 53240116Smarcel if(huge+x>one) return x; /* return x inexact except 0 */ 54240116Smarcel } 55240116Smarcel if(ix>0x41b00000) { /* |x| > 2**28 */ 56240116Smarcel w = __ieee754_log(fabs(x))+ln2; 57240116Smarcel } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ 58240116Smarcel t = fabs(x); 59240116Smarcel w = __ieee754_log(2.0*t+one/(sqrt(x*x+one)+t)); 60240116Smarcel } else { /* 2.0 > |x| > 2**-28 */ 61240116Smarcel t = x*x; 62240116Smarcel w =log1p(fabs(x)+t/(one+sqrt(one+t))); 63240116Smarcel } 64240116Smarcel if(hx>0) return w; else return -w; 65240116Smarcel} 66240116Smarcel