[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / exhaustive / log1pf_test.cpp
blob2922f3ece37926e3293fc2b85a4ffef3ed00187d
1 //===-- Exhaustive test for log1pf ----------------------------------------===//
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/log1pf.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "utils/MPFRWrapper/MPFRUtils.h"
15 using FPBits = __llvm_libc::fputil::FPBits<float>;
17 namespace mpfr = __llvm_libc::testing::mpfr;
19 struct LlvmLibcLog1pfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20 bool check(uint32_t start, uint32_t stop,
21 mpfr::RoundingMode rounding) override {
22 mpfr::ForceRoundingMode r(rounding);
23 uint32_t bits = start;
24 bool result = true;
25 do {
26 FPBits xbits(bits);
27 float x = float(xbits);
28 result &= EXPECT_MPFR_MATCH(mpfr::Operation::Log1p, x,
29 __llvm_libc::log1pf(x), 0.5, rounding);
30 } while (bits++ < stop);
31 return result;
35 // Range: All non-negative;
36 static constexpr uint32_t START = 0x0000'0000U;
37 static constexpr uint32_t STOP = 0x7f80'0000U;
39 TEST_F(LlvmLibcLog1pfExhaustiveTest, RoundNearestTieToEven) {
40 test_full_range(START, STOP, mpfr::RoundingMode::Nearest);
43 TEST_F(LlvmLibcLog1pfExhaustiveTest, RoundUp) {
44 test_full_range(START, STOP, mpfr::RoundingMode::Upward);
47 TEST_F(LlvmLibcLog1pfExhaustiveTest, RoundDown) {
48 test_full_range(START, STOP, mpfr::RoundingMode::Downward);
51 TEST_F(LlvmLibcLog1pfExhaustiveTest, RoundTowardZero) {
52 test_full_range(START, STOP, mpfr::RoundingMode::TowardZero);
55 // Range: [-1, 0];
56 static constexpr uint32_t NEG_START = 0x8000'0000U;
57 static constexpr uint32_t NEG_STOP = 0xbf7f'ffffU;
59 TEST_F(LlvmLibcLog1pfExhaustiveTest, NegativeRoundNearestTieToEven) {
60 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Nearest);
63 TEST_F(LlvmLibcLog1pfExhaustiveTest, NegativeRoundUp) {
64 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Upward);
67 TEST_F(LlvmLibcLog1pfExhaustiveTest, NegativeRoundDown) {
68 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Downward);
71 TEST_F(LlvmLibcLog1pfExhaustiveTest, NegativeRoundTowardZero) {
72 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::TowardZero);