1 | //===-- Unittests 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 | //===----------------------------------------------------------------------===// |
8 | |
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 | |
15 | #include <errno.h> |
16 | #include <stdint.h> |
17 | |
18 | using LlvmLibcLog10fTest = LIBC_NAMESPACE::testing::FPTest<float>; |
19 | |
20 | TEST_F(LlvmLibcLog10fTest, SpecialNumbers) { |
21 | EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::log10f(aNaN)); |
22 | EXPECT_FP_EQ(inf, LIBC_NAMESPACE::log10f(inf)); |
23 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(neg_inf), FE_INVALID); |
24 | EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log10f(0.0f), |
25 | FE_DIVBYZERO); |
26 | EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log10f(-0.0f), |
27 | FE_DIVBYZERO); |
28 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(-1.0f), FE_INVALID); |
29 | EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::log10f(1.0f)); |
30 | |
31 | float x = 1.0f; |
32 | for (int i = 0; i < 11; ++i, x *= 10.0f) { |
33 | EXPECT_FP_EQ_ALL_ROUNDING(static_cast<float>(i), LIBC_NAMESPACE::log10f(x)); |
34 | } |
35 | } |
36 | |