1 //===-- Unittests for atanf -----------------------------------------------===//
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 "hdr/math_macros.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/errno/libc_errno.h"
12 #include "src/math/atanf.h"
13 #include "test/UnitTest/FPMatcher.h"
14 #include "test/UnitTest/Test.h"
15 #include "utils/MPFRWrapper/MPFRUtils.h"
19 using LlvmLibcAtanfTest
= LIBC_NAMESPACE::testing::FPTest
<float>;
21 namespace mpfr
= LIBC_NAMESPACE::testing::mpfr
;
23 // TODO: This test needs to have its checks for exceptions, errno
25 TEST_F(LlvmLibcAtanfTest
, SpecialNumbers
) {
26 LIBC_NAMESPACE::libc_errno
= 0;
27 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT
);
28 EXPECT_FP_EQ_ALL_ROUNDING(aNaN
, LIBC_NAMESPACE::atanf(aNaN
));
29 // TODO: Uncomment these checks later, RoundingMode affects running
30 // tests in this way https://github.com/llvm/llvm-project/issues/90653.
31 // EXPECT_FP_EXCEPTION(0);
34 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT
);
35 EXPECT_FP_EQ_ALL_ROUNDING(0.0f
, LIBC_NAMESPACE::atanf(0.0f
));
36 // TODO: Uncomment these checks later, RoundingMode affects running
37 // tests in this way https://github.com/llvm/llvm-project/issues/90653.
38 // EXPECT_FP_EXCEPTION(0);
41 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT
);
42 EXPECT_FP_EQ_ALL_ROUNDING(-0.0f
, LIBC_NAMESPACE::atanf(-0.0f
));
43 // TODO: Uncomment these checks later, RoundingMode affects running
44 // tests in this way https://github.com/llvm/llvm-project/issues/90653.
45 // EXPECT_FP_EXCEPTION(0);
49 TEST_F(LlvmLibcAtanfTest
, InFloatRange
) {
50 constexpr uint32_t COUNT
= 100'000;
51 const uint32_t STEP
= FPBits(inf
).uintval() / COUNT
;
52 for (uint32_t i
= 0, v
= 0; i
<= COUNT
; ++i
, v
+= STEP
) {
53 float x
= FPBits(v
).get_val();
54 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan
, x
,
55 LIBC_NAMESPACE::atanf(x
), 0.5);
56 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan
, -x
,
57 LIBC_NAMESPACE::atanf(-x
), 0.5);
61 // For small values, tanh(x) is x.
62 TEST_F(LlvmLibcAtanfTest
, SpecialValues
) {
63 uint32_t val_arr
[] = {
64 0x3d8d6b23U
, // x = 0x1.1ad646p-4f
65 0x3dbb6ac7U
, // x = 0x1.76d58ep-4f
66 0x3feefcfbU
, // x = 0x1.ddf9f6p+0f
67 0x3ffe2ec1U
, // x = 0x1.fc5d82p+0f
68 0xbd8d6b23U
, // x = -0x1.1ad646p-4f
69 0xbdbb6ac7U
, // x = -0x1.76d58ep-4f
70 0xbfeefcfbU
, // x = -0x1.ddf9f6p+0f
71 0xbffe2ec1U
, // x = -0x1.fc5d82p+0
72 0x7F800000U
, // x = +Inf
73 0xFF800000U
, // x = -Inf
75 for (uint32_t v
: val_arr
) {
76 float x
= FPBits(v
).get_val();
77 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan
, x
,
78 LIBC_NAMESPACE::atanf(x
), 0.5);