blob: 602a8f042f7835ee6322ce5d34558af7391bc5f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
//===-- Single-precision atanh function -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "src/math/atanhf.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/math/generic/explogxf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, atanhf, (float x)) {
using namespace acoshf_internal;
using FPBits = typename fputil::FPBits<float>;
FPBits xbits(x);
Sign sign = xbits.sign();
uint32_t x_abs = xbits.abs().uintval();
// |x| >= 1.0
if (LIBC_UNLIKELY(x_abs >= 0x3F80'0000U)) {
if (xbits.is_nan()) {
if (xbits.is_signaling_nan()) {
fputil::raise_except_if_required(FE_INVALID);
return FPBits::quiet_nan().get_val();
}
return x;
}
// |x| == 1.0
if (x_abs == 0x3F80'0000U) {
fputil::set_errno_if_required(ERANGE);
fputil::raise_except_if_required(FE_DIVBYZERO);
return FPBits::inf(sign).get_val();
} else {
fputil::set_errno_if_required(EDOM);
fputil::raise_except_if_required(FE_INVALID);
return FPBits::quiet_nan().get_val();
}
}
// |x| < ~0.10
if (LIBC_UNLIKELY(x_abs <= 0x3dcc'0000U)) {
// |x| <= 2^-26
if (LIBC_UNLIKELY(x_abs <= 0x3280'0000U)) {
return static_cast<float>(LIBC_UNLIKELY(x_abs == 0)
? x
: (x + 0x1.5555555555555p-2 * x * x * x));
}
double xdbl = x;
double x2 = xdbl * xdbl;
// Pure Taylor series.
double pe = fputil::polyeval(x2, 0.0, 0x1.5555555555555p-2,
0x1.999999999999ap-3, 0x1.2492492492492p-3,
0x1.c71c71c71c71cp-4, 0x1.745d1745d1746p-4);
return static_cast<float>(fputil::multiply_add(xdbl, pe, xdbl));
}
double xdbl = x;
return static_cast<float>(0.5 * log_eval((xdbl + 1.0) / (xdbl - 1.0)));
}
} // namespace LIBC_NAMESPACE_DECL
|