| 1 | /* Copyright (C) 2011-2020 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | Contributed by Ulrich Drepper <drepper@gmail.com>, 2011. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | |
| 20 | /* __ieee754_atanh(x) |
| 21 | Method : |
| 22 | 1.Reduced x to positive by atanh(-x) = -atanh(x) |
| 23 | 2.For x>=0.5 |
| 24 | 1 2x x |
| 25 | atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) |
| 26 | 2 1 - x 1 - x |
| 27 | |
| 28 | For x<0.5 |
| 29 | atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) |
| 30 | |
| 31 | Special cases: |
| 32 | atanh(x) is NaN if |x| > 1 with signal; |
| 33 | atanh(NaN) is that NaN with no signal; |
| 34 | atanh(+-1) is +-INF with signal. |
| 35 | |
| 36 | */ |
| 37 | |
| 38 | #include <float.h> |
| 39 | #include <inttypes.h> |
| 40 | #include <math.h> |
| 41 | #include <math-barriers.h> |
| 42 | #include <math_private.h> |
| 43 | #include <math-underflow.h> |
| 44 | #include <libm-alias-finite.h> |
| 45 | |
| 46 | static const double huge = 1e300; |
| 47 | |
| 48 | double |
| 49 | __ieee754_atanh (double x) |
| 50 | { |
| 51 | double xa = fabs (x); |
| 52 | double t; |
| 53 | if (isless (xa, 0.5)) |
| 54 | { |
| 55 | if (__glibc_unlikely (xa < 0x1.0p-28)) |
| 56 | { |
| 57 | math_force_eval (huge + x); |
| 58 | math_check_force_underflow (x); |
| 59 | return x; |
| 60 | } |
| 61 | |
| 62 | t = xa + xa; |
| 63 | t = 0.5 * __log1p (t + t * xa / (1.0 - xa)); |
| 64 | } |
| 65 | else if (__glibc_likely (isless (xa, 1.0))) |
| 66 | t = 0.5 * __log1p ((xa + xa) / (1.0 - xa)); |
| 67 | else |
| 68 | { |
| 69 | if (isgreater (xa, 1.0)) |
| 70 | return (x - x) / (x - x); |
| 71 | |
| 72 | return x / 0.0; |
| 73 | } |
| 74 | |
| 75 | return copysign (t, x); |
| 76 | } |
| 77 | libm_alias_finite (__ieee754_atanh, __atanh) |
| 78 | |