1 | //===-- Unittests for exp10f ----------------------------------------------===// |
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/errno/libc_errno.h" |
12 | #include "src/math/exp10f.h" |
13 | #include "test/UnitTest/FPMatcher.h" |
14 | #include "test/UnitTest/Test.h" |
15 | |
16 | #include <stdint.h> |
17 | |
18 | using LlvmLibcExp10fTest = LIBC_NAMESPACE::testing::FPTest<float>; |
19 | |
20 | TEST_F(LlvmLibcExp10fTest, SpecialNumbers) { |
21 | LIBC_NAMESPACE::libc_errno = 0; |
22 | |
23 | EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::exp10f(aNaN)); |
24 | EXPECT_MATH_ERRNO(0); |
25 | |
26 | EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::exp10f(inf)); |
27 | EXPECT_MATH_ERRNO(0); |
28 | |
29 | EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::exp10f(neg_inf)); |
30 | EXPECT_MATH_ERRNO(0); |
31 | |
32 | EXPECT_FP_EQ_ALL_ROUNDING(1.0f, LIBC_NAMESPACE::exp10f(0.0f)); |
33 | EXPECT_MATH_ERRNO(0); |
34 | |
35 | EXPECT_FP_EQ_ALL_ROUNDING(1.0f, LIBC_NAMESPACE::exp10f(-0.0f)); |
36 | EXPECT_MATH_ERRNO(0); |
37 | |
38 | EXPECT_FP_EQ_ALL_ROUNDING(10.0f, LIBC_NAMESPACE::exp10f(1.0f)); |
39 | EXPECT_FP_EQ_ALL_ROUNDING(100.0f, LIBC_NAMESPACE::exp10f(2.0f)); |
40 | EXPECT_FP_EQ_ALL_ROUNDING(1000.0f, LIBC_NAMESPACE::exp10f(3.0f)); |
41 | } |
42 | |
43 | TEST_F(LlvmLibcExp10fTest, Overflow) { |
44 | LIBC_NAMESPACE::libc_errno = 0; |
45 | EXPECT_FP_EQ_WITH_EXCEPTION( |
46 | inf, LIBC_NAMESPACE::exp10f(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW); |
47 | EXPECT_MATH_ERRNO(ERANGE); |
48 | |
49 | EXPECT_FP_EQ_WITH_EXCEPTION( |
50 | inf, LIBC_NAMESPACE::exp10f(FPBits(0x43000000U).get_val()), FE_OVERFLOW); |
51 | EXPECT_MATH_ERRNO(ERANGE); |
52 | |
53 | EXPECT_FP_EQ_WITH_EXCEPTION( |
54 | inf, LIBC_NAMESPACE::exp10f(FPBits(0x43000001U).get_val()), FE_OVERFLOW); |
55 | EXPECT_MATH_ERRNO(ERANGE); |
56 | } |
57 | |