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 //===----------------------------------------------------------------------===//
8 
9 #include "exhaustive_test.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/math/log1pf.h"
12 #include "utils/MPFRWrapper/MPFRUtils.h"
13 #include "utils/UnitTest/FPMatcher.h"
14 
15 using FPBits = __llvm_libc::fputil::FPBits<float>;
16 
17 namespace mpfr = __llvm_libc::testing::mpfr;
18 
19 struct LlvmLibclog1pfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
checkLlvmLibclog1pfExhaustiveTest20   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;
32   }
33 };
34 
35 // Range: All non-negative;
36 static constexpr uint32_t START = 0x0000'0000U;
37 static constexpr uint32_t STOP = 0x7f80'0000U;
38 // Range: [-1, 0];
39 // static constexpr uint32_t START = 0x8000'0000U;
40 // static constexpr uint32_t STOP  = 0xbf80'0000U;
41 
TEST_F(LlvmLibclog1pfExhaustiveTest,RoundNearestTieToEven)42 TEST_F(LlvmLibclog1pfExhaustiveTest, RoundNearestTieToEven) {
43   test_full_range(START, STOP, mpfr::RoundingMode::Nearest);
44 }
45 
TEST_F(LlvmLibclog1pfExhaustiveTest,RoundUp)46 TEST_F(LlvmLibclog1pfExhaustiveTest, RoundUp) {
47   test_full_range(START, STOP, mpfr::RoundingMode::Upward);
48 }
49 
TEST_F(LlvmLibclog1pfExhaustiveTest,RoundDown)50 TEST_F(LlvmLibclog1pfExhaustiveTest, RoundDown) {
51   test_full_range(START, STOP, mpfr::RoundingMode::Downward);
52 }
53 
TEST_F(LlvmLibclog1pfExhaustiveTest,RoundTowardZero)54 TEST_F(LlvmLibclog1pfExhaustiveTest, RoundTowardZero) {
55   test_full_range(START, STOP, mpfr::RoundingMode::TowardZero);
56 }
57