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/config.h"
12 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
13 #include "src/math/generic/explogxf.h"
15 namespace LIBC_NAMESPACE_DECL
{
17 LLVM_LIBC_FUNCTION(float, atanhf
, (float x
)) {
18 using FPBits
= typename
fputil::FPBits
<float>;
21 Sign sign
= xbits
.sign();
22 uint32_t x_abs
= xbits
.abs().uintval();
25 if (LIBC_UNLIKELY(x_abs
>= 0x3F80'0000U
)) {
30 if (x_abs
== 0x3F80'0000U
) {
31 fputil::set_errno_if_required(ERANGE
);
32 fputil::raise_except_if_required(FE_DIVBYZERO
);
33 return FPBits::inf(sign
).get_val();
35 fputil::set_errno_if_required(EDOM
);
36 fputil::raise_except_if_required(FE_INVALID
);
37 return FPBits::quiet_nan().get_val();
42 if (LIBC_UNLIKELY(x_abs
<= 0x3dcc'0000U
)) {
44 if (LIBC_UNLIKELY(x_abs
<= 0x3280'0000U
)) {
45 return static_cast<float>(LIBC_UNLIKELY(x_abs
== 0)
47 : (x
+ 0x1.5555555555555p
-2 * x
* x
* x
));
51 double x2
= xdbl
* xdbl
;
52 // Pure Taylor series.
53 double pe
= fputil::polyeval(x2
, 0.0, 0x1.5555555555555p
-2,
54 0x1.999999999999ap
-3, 0x1.2492492492492p
-3,
55 0x1.c71c71c71c71cp
-4, 0x1.745d1745d1746p
-4);
56 return static_cast<float>(fputil::multiply_add(xdbl
, pe
, xdbl
));
59 return static_cast<float>(0.5 * log_eval((xdbl
+ 1.0) / (xdbl
- 1.0)));
62 } // namespace LIBC_NAMESPACE_DECL