13f708241SDavid Schultz 23f708241SDavid Schultz /* @(#)e_atanh.c 1.3 95/01/18 */ 33a8617a8SJordan K. Hubbard /* 43a8617a8SJordan K. Hubbard * ==================================================== 53a8617a8SJordan K. Hubbard * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 63a8617a8SJordan K. Hubbard * 73f708241SDavid Schultz * Developed at SunSoft, a Sun Microsystems, Inc. business. 83a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this 93a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice 103a8617a8SJordan K. Hubbard * is preserved. 113a8617a8SJordan K. Hubbard * ==================================================== 123f708241SDavid Schultz * 133a8617a8SJordan K. Hubbard */ 143a8617a8SJordan K. Hubbard 155aa554c7SDavid Schultz #include <sys/cdefs.h> 165aa554c7SDavid Schultz __FBSDID("$FreeBSD$"); 173a8617a8SJordan K. Hubbard 183a8617a8SJordan K. Hubbard /* __ieee754_atanh(x) 193a8617a8SJordan K. Hubbard * Method : 203a8617a8SJordan K. Hubbard * 1.Reduced x to positive by atanh(-x) = -atanh(x) 213a8617a8SJordan K. Hubbard * 2.For x>=0.5 223a8617a8SJordan K. Hubbard * 1 2x x 233a8617a8SJordan K. Hubbard * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) 243a8617a8SJordan K. Hubbard * 2 1 - x 1 - x 253a8617a8SJordan K. Hubbard * 263a8617a8SJordan K. Hubbard * For x<0.5 273a8617a8SJordan K. Hubbard * atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) 283a8617a8SJordan K. Hubbard * 293a8617a8SJordan K. Hubbard * Special cases: 303a8617a8SJordan K. Hubbard * atanh(x) is NaN if |x| > 1 with signal; 313a8617a8SJordan K. Hubbard * atanh(NaN) is that NaN with no signal; 323a8617a8SJordan K. Hubbard * atanh(+-1) is +-INF with signal. 333a8617a8SJordan K. Hubbard * 343a8617a8SJordan K. Hubbard */ 353a8617a8SJordan K. Hubbard 36*998b640bSDavid Schultz #include <float.h> 37*998b640bSDavid Schultz 383a8617a8SJordan K. Hubbard #include "math.h" 393a8617a8SJordan K. Hubbard #include "math_private.h" 403a8617a8SJordan K. Hubbard 413a8617a8SJordan K. Hubbard static const double one = 1.0, huge = 1e300; 423a8617a8SJordan K. Hubbard static const double zero = 0.0; 433a8617a8SJordan K. Hubbard 44a82bbc73SAlfred Perlstein double 45a82bbc73SAlfred Perlstein __ieee754_atanh(double x) 463a8617a8SJordan K. Hubbard { 473a8617a8SJordan K. Hubbard double t; 483a8617a8SJordan K. Hubbard int32_t hx,ix; 493a8617a8SJordan K. Hubbard u_int32_t lx; 503a8617a8SJordan K. Hubbard EXTRACT_WORDS(hx,lx,x); 513a8617a8SJordan K. Hubbard ix = hx&0x7fffffff; 523a8617a8SJordan K. Hubbard if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */ 533a8617a8SJordan K. Hubbard return (x-x)/(x-x); 543a8617a8SJordan K. Hubbard if(ix==0x3ff00000) 553a8617a8SJordan K. Hubbard return x/zero; 563a8617a8SJordan K. Hubbard if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */ 573a8617a8SJordan K. Hubbard SET_HIGH_WORD(x,ix); 583a8617a8SJordan K. Hubbard if(ix<0x3fe00000) { /* x < 0.5 */ 593a8617a8SJordan K. Hubbard t = x+x; 603a8617a8SJordan K. Hubbard t = 0.5*log1p(t+t*x/(one-x)); 613a8617a8SJordan K. Hubbard } else 623a8617a8SJordan K. Hubbard t = 0.5*log1p((x+x)/(one-x)); 633a8617a8SJordan K. Hubbard if(hx>=0) return t; else return -t; 643a8617a8SJordan K. Hubbard } 65*998b640bSDavid Schultz 66*998b640bSDavid Schultz #if LDBL_MANT_DIG == 53 67*998b640bSDavid Schultz __weak_reference(atanh, atanhl); 68*998b640bSDavid Schultz #endif 69