[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / math / generic / atanf.cpp
blobed7847adb15a1fb2a48cf225044b3cedf6b27f71
1 //===-- Single-precision atan function ------------------------------------===//
2 //
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
6 //
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>;
19 FPBits xbits(x);
20 bool sign = xbits.get_sign();
21 xbits.set_sign(false);
23 if (LIBC_UNLIKELY(xbits.is_inf_or_nan())) {
24 if (xbits.is_inf())
25 return static_cast<float>(opt_barrier(sign ? -M_MATH_PI_2 : M_MATH_PI_2));
26 else
27 return x;
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);
34 br.set_sign(sign);
35 return br.get_val();
39 // |x| == 1.8670953512191772
40 if (LIBC_UNLIKELY(xbits.uintval() == 0x3feefcfbU)) {
41 int rounding_mode = fputil::get_round();
42 if (sign) {
43 if (rounding_mode == FE_DOWNWARD) {
44 // -1.0790828466415405
45 return FPBits(0xbf8a1f63U).get_val();
47 } else {
48 if (rounding_mode == FE_UPWARD) {
49 // 1.0790828466415405
50 return FPBits(0x3f8a1f63U).get_val();
55 return static_cast<float>(atan_eval(x));
58 } // namespace __llvm_libc