[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / exhaustive / tanf_test.cpp
blob2bf95a9b3682a5871c98bbed9d4fbda89e1a106a
1 //===-- Exhaustive test for tanf
2 //--------------------------------------std::cout----===//
3 //
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
7 //
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"
16 #include <thread>
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;
29 bool result = true;
30 int tol = TOLERANCE;
31 do {
32 FPBits xbits(bits);
33 float x = float(xbits);
34 bool r = EXPECT_MPFR_MATCH(mpfr::Operation::Tan, x, __llvm_libc::tanf(x),
35 0.5, rounding);
36 result &= r;
37 if (!r)
38 --tol;
39 if (!tol)
40 break;
41 } while (++bits < stop);
42 return result;
46 // Range: [0, +Inf);
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);
66 // Range: (-Inf, 0];
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);