1*e581841eSTue Ly //===-- Exhaustive test for log10f ----------------------------------------===//
2*e581841eSTue Ly //
3*e581841eSTue Ly // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e581841eSTue Ly // See https://llvm.org/LICENSE.txt for license information.
5*e581841eSTue Ly // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e581841eSTue Ly //
7*e581841eSTue Ly //===----------------------------------------------------------------------===//
8*e581841eSTue Ly 
9*e581841eSTue Ly #include "exhaustive_test.h"
10*e581841eSTue Ly #include "src/__support/FPUtil/FPBits.h"
11*e581841eSTue Ly #include "src/math/log10f.h"
12*e581841eSTue Ly #include "utils/MPFRWrapper/MPFRUtils.h"
13*e581841eSTue Ly #include "utils/UnitTest/FPMatcher.h"
14*e581841eSTue Ly 
15*e581841eSTue Ly using FPBits = __llvm_libc::fputil::FPBits<float>;
16*e581841eSTue Ly 
17*e581841eSTue Ly namespace mpfr = __llvm_libc::testing::mpfr;
18*e581841eSTue Ly 
19*e581841eSTue Ly struct LlvmLibcLog10fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
20*e581841eSTue Ly   void check(uint32_t start, uint32_t stop,
21*e581841eSTue Ly              mpfr::RoundingMode rounding) override {
22*e581841eSTue Ly     mpfr::ForceRoundingMode r(rounding);
23*e581841eSTue Ly     uint32_t bits = start;
24*e581841eSTue Ly     do {
25*e581841eSTue Ly       FPBits xbits(bits);
26*e581841eSTue Ly       float x = float(xbits);
27*e581841eSTue Ly       EXPECT_MPFR_MATCH(mpfr::Operation::Log10, x, __llvm_libc::log10f(x), 0.5,
28*e581841eSTue Ly                         rounding);
29*e581841eSTue Ly     } while (bits++ < stop);
30*e581841eSTue Ly   }
31*e581841eSTue Ly };
32*e581841eSTue Ly 
33*e581841eSTue Ly // Range: All non-negative;
34*e581841eSTue Ly static constexpr uint32_t START = 0x0000'0000U;
35*e581841eSTue Ly static constexpr uint32_t STOP = 0x7f80'0000U;
36*e581841eSTue Ly // Range: [1, 10];
37*e581841eSTue Ly // static constexpr uint32_t START = 0x3f80'0000U;
38*e581841eSTue Ly // static constexpr uint32_t STOP  = 0x41c0'0000U;
39*e581841eSTue Ly static constexpr int NUM_THREADS = 16;
40*e581841eSTue Ly 
41*e581841eSTue Ly TEST_F(LlvmLibcLog10fExhaustiveTest, RoundNearestTieToEven) {
42*e581841eSTue Ly   test_full_range(START, STOP, NUM_THREADS, mpfr::RoundingMode::Nearest);
43*e581841eSTue Ly }
44*e581841eSTue Ly 
45*e581841eSTue Ly TEST_F(LlvmLibcLog10fExhaustiveTest, RoundUp) {
46*e581841eSTue Ly   test_full_range(START, STOP, NUM_THREADS, mpfr::RoundingMode::Upward);
47*e581841eSTue Ly }
48*e581841eSTue Ly 
49*e581841eSTue Ly TEST_F(LlvmLibcLog10fExhaustiveTest, RoundDown) {
50*e581841eSTue Ly   test_full_range(START, STOP, NUM_THREADS, mpfr::RoundingMode::Downward);
51*e581841eSTue Ly }
52*e581841eSTue Ly 
53*e581841eSTue Ly TEST_F(LlvmLibcLog10fExhaustiveTest, RoundTowardZero) {
54*e581841eSTue Ly   test_full_range(START, STOP, NUM_THREADS, mpfr::RoundingMode::TowardZero);
55*e581841eSTue Ly }
56