1*1e651e1eSRoland Levillain 2*1e651e1eSRoland Levillain /* @(#)e_atanh.c 1.3 95/01/18 */ 3*1e651e1eSRoland Levillain /* 4*1e651e1eSRoland Levillain * ==================================================== 5*1e651e1eSRoland Levillain * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6*1e651e1eSRoland Levillain * 7*1e651e1eSRoland Levillain * Developed at SunSoft, a Sun Microsystems, Inc. business. 8*1e651e1eSRoland Levillain * Permission to use, copy, modify, and distribute this 9*1e651e1eSRoland Levillain * software is freely granted, provided that this notice 10*1e651e1eSRoland Levillain * is preserved. 11*1e651e1eSRoland Levillain * ==================================================== 12*1e651e1eSRoland Levillain * 13*1e651e1eSRoland Levillain */ 14*1e651e1eSRoland Levillain 15*1e651e1eSRoland Levillain /* __ieee754_atanh(x) 16*1e651e1eSRoland Levillain * Method : 17*1e651e1eSRoland Levillain * 1.Reduced x to positive by atanh(-x) = -atanh(x) 18*1e651e1eSRoland Levillain * 2.For x>=0.5 19*1e651e1eSRoland Levillain * 1 2x x 20*1e651e1eSRoland Levillain * atanh(x) = --- * ieee_log(1 + -------) = 0.5 * ieee_log1p(2 * --------) 21*1e651e1eSRoland Levillain * 2 1 - x 1 - x 22*1e651e1eSRoland Levillain * 23*1e651e1eSRoland Levillain * For x<0.5 24*1e651e1eSRoland Levillain * atanh(x) = 0.5*ieee_log1p(2x+2x*x/(1-x)) 25*1e651e1eSRoland Levillain * 26*1e651e1eSRoland Levillain * Special cases: 27*1e651e1eSRoland Levillain * atanh(x) is NaN if |x| > 1 with signal; 28*1e651e1eSRoland Levillain * atanh(NaN) is that NaN with no signal; 29*1e651e1eSRoland Levillain * atanh(+-1) is +-INF with signal. 30*1e651e1eSRoland Levillain * 31*1e651e1eSRoland Levillain */ 32*1e651e1eSRoland Levillain 33*1e651e1eSRoland Levillain #include "fdlibm.h" 34*1e651e1eSRoland Levillain 35*1e651e1eSRoland Levillain #ifdef __STDC__ 36*1e651e1eSRoland Levillain static const double one = 1.0, huge = 1e300; 37*1e651e1eSRoland Levillain #else 38*1e651e1eSRoland Levillain static double one = 1.0, huge = 1e300; 39*1e651e1eSRoland Levillain #endif 40*1e651e1eSRoland Levillain 41*1e651e1eSRoland Levillain static double zero = 0.0; 42*1e651e1eSRoland Levillain 43*1e651e1eSRoland Levillain #ifdef __STDC__ __ieee754_atanh(double x)44*1e651e1eSRoland Levillain double __ieee754_atanh(double x) 45*1e651e1eSRoland Levillain #else 46*1e651e1eSRoland Levillain double __ieee754_atanh(x) 47*1e651e1eSRoland Levillain double x; 48*1e651e1eSRoland Levillain #endif 49*1e651e1eSRoland Levillain { 50*1e651e1eSRoland Levillain double t; 51*1e651e1eSRoland Levillain int hx,ix; 52*1e651e1eSRoland Levillain unsigned lx; 53*1e651e1eSRoland Levillain hx = __HI(x); /* high word */ 54*1e651e1eSRoland Levillain lx = __LO(x); /* low word */ 55*1e651e1eSRoland Levillain ix = hx&0x7fffffff; 56*1e651e1eSRoland Levillain if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */ 57*1e651e1eSRoland Levillain return (x-x)/(x-x); 58*1e651e1eSRoland Levillain if(ix==0x3ff00000) 59*1e651e1eSRoland Levillain return x/zero; 60*1e651e1eSRoland Levillain if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */ 61*1e651e1eSRoland Levillain __HI(x) = ix; /* x <- |x| */ 62*1e651e1eSRoland Levillain if(ix<0x3fe00000) { /* x < 0.5 */ 63*1e651e1eSRoland Levillain t = x+x; 64*1e651e1eSRoland Levillain t = 0.5*ieee_log1p(t+t*x/(one-x)); 65*1e651e1eSRoland Levillain } else 66*1e651e1eSRoland Levillain t = 0.5*ieee_log1p((x+x)/(one-x)); 67*1e651e1eSRoland Levillain if(hx>=0) return t; else return -t; 68*1e651e1eSRoland Levillain } 69