OSDN Git Service

* Makefile.in (DLLTOOL_FLAGS): Remove -U.
[mingw/mingw-org-wsl.git] / src / libcrt / math / atanhf.c
1 #include <math.h>
2 #include <errno.h>
3 #include "fastmath.h"
4
5 /* atanh (x) = 0.5 * log ((1.0 + x)/(1.0 - x)) */
6 float atanhf (float x)
7 {
8   float z;
9   if isnan (x)
10     return x;
11   z = fabsf (x);
12   if (z == 1.0)
13     {
14       errno  = ERANGE;
15       return (x > 0 ? INFINITY : -INFINITY);
16     }
17   if ( z > 1.0)
18     {
19       errno = EDOM;
20       return nanf("");
21     }
22   /* Rearrange formula to avoid precision loss for small x.
23
24   atanh(x) = 0.5 * log ((1.0 + x)/(1.0 - x))
25            = 0.5 * log1p ((1.0 + x)/(1.0 - x) - 1.0)
26            = 0.5 * log1p ((1.0 + x - 1.0 + x) /(1.0 - x)) 
27            = 0.5 * log1p ((2.0 * x ) / (1.0 - x))  */
28   z = 0.5 * __fast_log1p ((z + z) / (1.0 - z));
29   return x >= 0 ? z : -z;
30 }