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