[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / exhaustive / log10f_test.cpp
blobdcf345e2cd8a4cc1abeb8cb4240ed389712d20af
1 //===-- Exhaustive test for log10f ----------------------------------------===//
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/log10f.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 LlvmLibcLog10fExhaustiveTest : 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::Log10, x,
29 __llvm_libc::log10f(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;
38 // Range: [1, 10];
39 // static constexpr uint32_t START = 0x3f80'0000U;
40 // static constexpr uint32_t STOP = 0x41c0'0000U;
41 TEST_F(LlvmLibcLog10fExhaustiveTest, RoundNearestTieToEven) {
42 test_full_range(START, STOP, mpfr::RoundingMode::Nearest);
45 TEST_F(LlvmLibcLog10fExhaustiveTest, RoundUp) {
46 test_full_range(START, STOP, mpfr::RoundingMode::Upward);
49 TEST_F(LlvmLibcLog10fExhaustiveTest, RoundDown) {
50 test_full_range(START, STOP, mpfr::RoundingMode::Downward);
53 TEST_F(LlvmLibcLog10fExhaustiveTest, RoundTowardZero) {
54 test_full_range(START, STOP, mpfr::RoundingMode::TowardZero);