[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / exhaustive / tanhf_test.cpp
blob2b01118a1a922b158079ca1f5040d1167ef2b4a5
1 //===-- Exhaustive test for tanhf -----------------------------------------===//
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 "exhaustive_test.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/math/tanhf.h"
12 #include "utils/MPFRWrapper/MPFRUtils.h"
14 #include <thread>
16 using FPBits = __llvm_libc::fputil::FPBits<float>;
18 namespace mpfr = __llvm_libc::testing::mpfr;
20 struct LlvmLibcTanhfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
21 bool check(uint32_t start, uint32_t stop,
22 mpfr::RoundingMode rounding) override {
23 mpfr::ForceRoundingMode r(rounding);
24 uint32_t bits = start;
25 bool result = true;
26 do {
27 FPBits xbits(bits);
28 float x = float(xbits);
29 result &= EXPECT_MPFR_MATCH(mpfr::Operation::Tanh, x,
30 __llvm_libc::tanhf(x), 0.5, rounding);
31 } while (bits++ < stop);
32 return result;
36 static const int NUM_THREADS = std::thread::hardware_concurrency();
38 // Range: [0, INF];
39 static const uint32_t POS_START = 0x0000'0000U;
40 static const uint32_t POS_STOP = FPBits::inf(false).uintval();
42 TEST_F(LlvmLibcTanhfExhaustiveTest, PostiveRangeRoundNearestTieToEven) {
43 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Nearest);
46 TEST_F(LlvmLibcTanhfExhaustiveTest, PostiveRangeRoundUp) {
47 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Upward);
50 TEST_F(LlvmLibcTanhfExhaustiveTest, PostiveRangeRoundDown) {
51 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Downward);
54 TEST_F(LlvmLibcTanhfExhaustiveTest, PostiveRangeRoundTowardZero) {
55 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::TowardZero);
58 // Range: [-INF, 0];
59 static const uint32_t NEG_START = 0x8000'0000U;
60 static const uint32_t NEG_STOP = FPBits::inf(true).uintval();
62 TEST_F(LlvmLibcTanhfExhaustiveTest, NegativeRangeRoundNearestTieToEven) {
63 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Nearest);
66 TEST_F(LlvmLibcTanhfExhaustiveTest, NegativeRangeRoundUp) {
67 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Upward);
70 TEST_F(LlvmLibcTanhfExhaustiveTest, NegativeRangeRoundDown) {
71 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Downward);
74 TEST_F(LlvmLibcTanhfExhaustiveTest, NegativeRangeRoundTowardZero) {
75 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::TowardZero);