POK
e_atanh.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Jan 30 14:41:34 2009
15  */
16 
17 /* @(#)e_atanh.c 5.1 93/09/24 */
18 /*
19  * ====================================================
20  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
21  *
22  * Developed at SunPro, a Sun Microsystems, Inc. business.
23  * Permission to use, copy, modify, and distribute this
24  * software is freely granted, provided that this notice
25  * is preserved.
26  * ====================================================
27  */
28 
29 /* __ieee754_atanh(x)
30  * Method :
31  * 1.Reduced x to positive by atanh(-x) = -atanh(x)
32  * 2.For x>=0.5
33  * 1 2x x
34  * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
35  * 2 1 - x 1 - x
36  *
37  * For x<0.5
38  * atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
39  *
40  * Special cases:
41  * atanh(x) is NaN if |x| > 1 with signal;
42  * atanh(NaN) is that NaN with no signal;
43  * atanh(+-1) is +-INF with signal.
44  *
45  */
46 #ifdef POK_NEEDS_LIBMATH
47 
48 #include <libm.h>
49 #include "math_private.h"
50 
51 static const double one = 1.0, huge = 1e300;
52 
53 static const double zero = 0.0;
54 
55 double
56 __ieee754_atanh(double x)
57 {
58  double t;
59  int32_t hx,ix;
60  uint32_t lx;
61  EXTRACT_WORDS(hx,lx,x);
62  ix = hx&0x7fffffff;
63  if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
64  return (x-x)/(x-x);
65  if(ix==0x3ff00000)
66  return x/zero;
67  if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */
68  SET_HIGH_WORD(x,ix);
69  if(ix<0x3fe00000) { /* x < 0.5 */
70  t = x+x;
71  t = 0.5*log1p(t+t*x/(one-x));
72  } else
73  t = 0.5*log1p((x+x)/(one-x));
74  if(hx>=0) return t; else return -t;
75 }
76 #endif