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 "src/__support/FPUtil/FPBits.h"
10 #include "src/math/atanf.h"
11 #include "test/UnitTest/FPMatcher.h"
12 #include "test/UnitTest/Test.h"
13 #include "utils/MPFRWrapper/MPFRUtils.h"
19 #include <initializer_list>
21 using FPBits
= __llvm_libc::fputil::FPBits
<float>;
23 namespace mpfr
= __llvm_libc::testing::mpfr
;
25 DECLARE_SPECIAL_CONSTANTS(float)
27 TEST(LlvmLibcAtanfTest
, SpecialNumbers
) {
29 __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT
);
30 EXPECT_FP_EQ(aNaN
, __llvm_libc::atanf(aNaN
));
31 EXPECT_FP_EXCEPTION(0);
34 __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT
);
35 EXPECT_FP_EQ(0.0f
, __llvm_libc::atanf(0.0f
));
36 EXPECT_FP_EXCEPTION(0);
39 __llvm_libc::fputil::clear_except(FE_ALL_EXCEPT
);
40 EXPECT_FP_EQ(-0.0f
, __llvm_libc::atanf(-0.0f
));
41 EXPECT_FP_EXCEPTION(0);
45 TEST(LlvmLibcAtanfTest
, InFloatRange
) {
46 constexpr uint32_t COUNT
= 1000000;
47 const uint32_t STEP
= FPBits(inf
).uintval() / COUNT
;
48 for (uint32_t i
= 0, v
= 0; i
<= COUNT
; ++i
, v
+= STEP
) {
49 float x
= float(FPBits(v
));
50 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan
, x
,
51 __llvm_libc::atanf(x
), 0.5);
52 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan
, -x
,
53 __llvm_libc::atanf(-x
), 0.5);
57 // For small values, tanh(x) is x.
58 TEST(LlvmLibcAtanfTest
, SpecialValues
) {
59 for (uint32_t v
: {0x3d8d6b23U
, 0x3feefcfbU
, 0xbd8d6b23U
, 0xbfeefcfbU
,
60 0x7F800000U
, 0xFF800000U
}) {
61 float x
= float(FPBits(v
));
62 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan
, x
,
63 __llvm_libc::atanf(x
), 0.5);