1 //===-- Unittests for log10f ----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "hdr/math_macros.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/math/log10f.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "test/UnitTest/Test.h"
14 #include "utils/MPFRWrapper/MPFRUtils.h"
18 using LlvmLibcLog10fTest
= LIBC_NAMESPACE::testing::FPTest
<float>;
20 namespace mpfr
= LIBC_NAMESPACE::testing::mpfr
;
22 TEST_F(LlvmLibcLog10fTest
, SpecialNumbers
) {
23 EXPECT_FP_EQ(aNaN
, LIBC_NAMESPACE::log10f(aNaN
));
24 EXPECT_FP_EQ(inf
, LIBC_NAMESPACE::log10f(inf
));
25 EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(neg_inf
), FE_INVALID
);
26 EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf
, LIBC_NAMESPACE::log10f(0.0f
),
28 EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf
, LIBC_NAMESPACE::log10f(-0.0f
),
30 EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(-1.0f
), FE_INVALID
);
31 EXPECT_FP_EQ_ALL_ROUNDING(zero
, LIBC_NAMESPACE::log10f(1.0f
));
34 TEST_F(LlvmLibcLog10fTest
, TrickyInputs
) {
36 constexpr uint32_t INPUTS
[N
] = {
38 0x41200000U
/*10.0f*/,
39 0x42c80000U
/*100.0f*/,
40 0x447a0000U
/*1,000.0f*/,
41 0x461c4000U
/*10,000.0f*/,
42 0x47c35000U
/*100,000.0f*/,
43 0x49742400U
/*1,000,000.0f*/,
44 0x4b189680U
/*10,000,000.0f*/,
45 0x4cbebc20U
/*100,000,000.0f*/,
46 0x4e6e6b28U
/*1,000,000,000.0f*/,
47 0x501502f9U
/*10,000,000,000.0f*/,
48 0x4f134f83U
/*2471461632.0f*/,
49 0x7956ba5eU
/*69683218960000541503257137270226944.0f*/,
50 0x08ae'a356U
/*0x1.5d46acp-110f*/,
51 0x1c7d'a337U
/*0x1.fb466ep-71f*/,
52 0x69c8'c583U
/*0x1.918b06p+84f*/,
53 0x0efe'ee7aU
/*0x1.fddcf4p-98f*/,
54 0x3f5f'de1bU
/*0x1.bfbc36p-1f*/,
55 0x3f80'70d8U
/*0x1.00e1bp0f*/,
56 0x120b'93dcU
/*0x1.1727b8p-91f*/,
57 0x13ae'78d3U
/*0x1.5cf1a6p-88f*/,
60 for (int i
= 0; i
< N
; ++i
) {
61 float x
= FPBits(INPUTS
[i
]).get_val();
62 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10
, x
,
63 LIBC_NAMESPACE::log10f(x
), 0.5);
67 TEST_F(LlvmLibcLog10fTest
, InFloatRange
) {
68 constexpr uint32_t COUNT
= 100'000;
69 constexpr uint32_t STEP
= UINT32_MAX
/ COUNT
;
70 for (uint32_t i
= 0, v
= 0; i
<= COUNT
; ++i
, v
+= STEP
) {
71 float x
= FPBits(v
).get_val();
72 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10
, x
,
73 LIBC_NAMESPACE::log10f(x
), 0.5);