s_asinhl.c revision 22993
1139825Simp/* @(#)s_asinh.c 5.1 93/09/24 */ 21541Srgrimes/* 31541Srgrimes * ==================================================== 41541Srgrimes * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 51541Srgrimes * 61541Srgrimes * Developed at SunPro, a Sun Microsystems, Inc. business. 71541Srgrimes * Permission to use, copy, modify, and distribute this 81541Srgrimes * software is freely granted, provided that this notice 91541Srgrimes * is preserved. 101541Srgrimes * ==================================================== 111541Srgrimes */ 121541Srgrimes 131541Srgrimes#ifndef lint 141541Srgrimesstatic char rcsid[] = "$Id$"; 151541Srgrimes#endif 161541Srgrimes 171541Srgrimes/* asinh(x) 181541Srgrimes * Method : 191541Srgrimes * Based on 201541Srgrimes * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 211541Srgrimes * we have 221541Srgrimes * asinh(x) := x if 1+x*x=1, 231541Srgrimes * := sign(x)*(log(x)+ln2)) for large |x|, else 241541Srgrimes * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else 251541Srgrimes * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) 261541Srgrimes */ 271541Srgrimes 281541Srgrimes#include "math.h" 291541Srgrimes#include "math_private.h" 3050477Speter 311541Srgrimes#ifdef __STDC__ 321541Srgrimesstatic const double 332165Spaul#else 342811Sbdestatic double 352165Spaul#endif 36136745Sphkone = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ 371541Srgrimesln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ 38103187Sbdehuge= 1.00000000000000000000e+300; 39176708Sattilio 40103187Sbde#ifdef __STDC__ 41236317Skib double asinh(double x) 4270834Swollman#else 4334924Sbde double asinh(x) 4454803Srwatson double x; 45103849Sjeff#endif 461541Srgrimes{ 471541Srgrimes double t,w; 481541Srgrimes int32_t hx,ix; 491541Srgrimes GET_HIGH_WORD(hx,x); 501541Srgrimes ix = hx&0x7fffffff; 511541Srgrimes if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */ 521541Srgrimes if(ix< 0x3e300000) { /* |x|<2**-28 */ 531541Srgrimes if(huge+x>one) return x; /* return x inexact except 0 */ 541541Srgrimes } 551541Srgrimes if(ix>0x41b00000) { /* |x| > 2**28 */ 56154152Stegge w = __ieee754_log(fabs(x))+ln2; 57154152Stegge } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ 581541Srgrimes t = fabs(x); 591541Srgrimes w = __ieee754_log(2.0*t+one/(sqrt(x*x+one)+t)); 601541Srgrimes } else { /* 2.0 > |x| > 2**-28 */ 611541Srgrimes t = x*x; 621541Srgrimes w =log1p(fabs(x)+t/(one+sqrt(one+t))); 631541Srgrimes } 6459652Sgreen if(hx>0) return w; else return -w; 6512158Sbde} 6690791Sphk