1 //===-- Single-precision atanh function -----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/math/atanhf.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
12 #include "src/math/generic/explogxf.h"
14 namespace __llvm_libc
{
16 LLVM_LIBC_FUNCTION(float, atanhf
, (float x
)) {
17 using FPBits
= typename
fputil::FPBits
<float>;
19 bool sign
= xbits
.get_sign();
20 uint32_t x_abs
= xbits
.uintval() & FPBits::FloatProp::EXP_MANT_MASK
;
23 if (LIBC_UNLIKELY(x_abs
>= 0x3F80'0000U
)) {
28 if (x_abs
== 0x3F80'0000U
) {
29 fputil::set_errno_if_required(ERANGE
);
30 fputil::raise_except_if_required(FE_DIVBYZERO
);
31 return FPBits::inf(sign
).get_val();
33 fputil::set_errno_if_required(EDOM
);
34 fputil::raise_except_if_required(FE_INVALID
);
35 return FPBits::build_quiet_nan(0);
40 if (LIBC_UNLIKELY(x_abs
<= 0x3dcc'0000U
)) {
42 if (LIBC_UNLIKELY(x_abs
<= 0x3280'0000U
)) {
43 return static_cast<float>(LIBC_UNLIKELY(x_abs
== 0)
45 : (x
+ 0x1.5555555555555p
-2 * x
* x
* x
));
49 double x2
= xdbl
* xdbl
;
50 // Pure Taylor series.
51 double pe
= fputil::polyeval(x2
, 0.0, 0x1.5555555555555p
-2,
52 0x1.999999999999ap
-3, 0x1.2492492492492p
-3,
53 0x1.c71c71c71c71cp
-4, 0x1.745d1745d1746p
-4);
54 return static_cast<float>(fputil::multiply_add(xdbl
, pe
, xdbl
));
57 return static_cast<float>(0.5 * log_eval((xdbl
+ 1.0) / (xdbl
- 1.0)));
60 } // namespace __llvm_libc