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