1 //===-- Exhaustive test for tanf
2 //--------------------------------------std::cout----===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "exhaustive_test.h"
11 #include "src/__support/FPUtil/FPBits.h"
12 #include "src/math/tanf.h"
13 #include "test/UnitTest/FPMatcher.h"
14 #include "utils/MPFRWrapper/MPFRUtils.h"
18 using FPBits
= __llvm_libc::fputil::FPBits
<float>;
20 namespace mpfr
= __llvm_libc::testing::mpfr
;
22 static constexpr int TOLERANCE
= 3;
24 struct LlvmLibcTanfExhaustiveTest
: public LlvmLibcExhaustiveTest
<uint32_t> {
25 bool check(uint32_t start
, uint32_t stop
,
26 mpfr::RoundingMode rounding
) override
{
27 mpfr::ForceRoundingMode
r(rounding
);
28 uint32_t bits
= start
;
33 float x
= float(xbits
);
34 bool r
= EXPECT_MPFR_MATCH(mpfr::Operation::Tan
, x
, __llvm_libc::tanf(x
),
41 } while (++bits
< stop
);
47 static constexpr uint32_t POS_START
= 0x0000'0000U
;
48 static constexpr uint32_t POS_STOP
= 0x7f80'0000U
;
50 TEST_F(LlvmLibcTanfExhaustiveTest
, PostiveRangeRoundNearestTieToEven
) {
51 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::Nearest
);
54 TEST_F(LlvmLibcTanfExhaustiveTest
, PostiveRangeRoundUp
) {
55 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::Upward
);
58 TEST_F(LlvmLibcTanfExhaustiveTest
, PostiveRangeRoundDown
) {
59 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::Downward
);
62 TEST_F(LlvmLibcTanfExhaustiveTest
, PostiveRangeRoundTowardZero
) {
63 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::TowardZero
);
67 static constexpr uint32_t NEG_START
= 0x8000'0000U
;
68 static constexpr uint32_t NEG_STOP
= 0xff80'0000U
;
70 TEST_F(LlvmLibcTanfExhaustiveTest
, NegativeRangeRoundNearestTieToEven
) {
71 test_full_range(NEG_START
, NEG_STOP
, mpfr::RoundingMode::Nearest
);
74 TEST_F(LlvmLibcTanfExhaustiveTest
, NegativeRangeRoundUp
) {
75 test_full_range(NEG_START
, NEG_STOP
, mpfr::RoundingMode::Upward
);
78 TEST_F(LlvmLibcTanfExhaustiveTest
, NegativeRangeRoundDown
) {
79 test_full_range(NEG_START
, NEG_STOP
, mpfr::RoundingMode::Downward
);
82 TEST_F(LlvmLibcTanfExhaustiveTest
, NegativeRangeRoundTowardZero
) {
83 test_full_range(NEG_START
, NEG_STOP
, mpfr::RoundingMode::TowardZero
);