1 //===-- Single-precision atan 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/atanf.h"
10 #include "math_utils.h"
11 #include "src/__support/FPUtil/FPBits.h"
12 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
13 #include "src/math/generic/inv_trigf_utils.h"
15 namespace __llvm_libc
{
17 LLVM_LIBC_FUNCTION(float, atanf
, (float x
)) {
18 using FPBits
= typename
fputil::FPBits
<float>;
20 bool sign
= xbits
.get_sign();
21 xbits
.set_sign(false);
23 if (LIBC_UNLIKELY(xbits
.is_inf_or_nan())) {
25 return static_cast<float>(opt_barrier(sign
? -M_MATH_PI_2
: M_MATH_PI_2
));
29 // |x| == 0.06905200332403183
30 if (LIBC_UNLIKELY(xbits
.uintval() == 0x3d8d6b23U
)) {
31 if (fputil::get_round() == FE_TONEAREST
) {
32 // 0.06894256919622421
33 FPBits
br(0x3d8d31c3U
);
39 // |x| == 1.8670953512191772
40 if (LIBC_UNLIKELY(xbits
.uintval() == 0x3feefcfbU
)) {
41 int rounding_mode
= fputil::get_round();
43 if (rounding_mode
== FE_DOWNWARD
) {
44 // -1.0790828466415405
45 return FPBits(0xbf8a1f63U
).get_val();
48 if (rounding_mode
== FE_UPWARD
) {
50 return FPBits(0x3f8a1f63U
).get_val();
55 return static_cast<float>(atan_eval(x
));
58 } // namespace __llvm_libc