1 | //===-- Unittests for exp10m1f --------------------------------------------===// |
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/CPP/array.h" |
11 | #include "src/__support/libc_errno.h" |
12 | #include "src/math/exp10m1f.h" |
13 | #include "test/UnitTest/FPMatcher.h" |
14 | #include "test/UnitTest/Test.h" |
15 | #include "utils/MPFRWrapper/MPFRUtils.h" |
16 | |
17 | #include <stdint.h> |
18 | |
19 | using LlvmLibcExp10m1fTest = LIBC_NAMESPACE::testing::FPTest<float>; |
20 | |
21 | namespace mpfr = LIBC_NAMESPACE::testing::mpfr; |
22 | |
23 | TEST_F(LlvmLibcExp10m1fTest, TrickyInputs) { |
24 | constexpr LIBC_NAMESPACE::cpp::array<float, 39> INPUTS = { |
25 | // EXP10M1F_EXCEPTS_LO |
26 | 0x1.0fe54ep-11f, |
27 | 0x1.80e6eap-11f, |
28 | -0x1.2a33bcp-51f, |
29 | -0x0p+0f, |
30 | -0x1.b59e08p-31f, |
31 | -0x1.bf342p-12f, |
32 | -0x1.6207fp-11f, |
33 | -0x1.bd0c66p-11f, |
34 | -0x1.ffd84cp-10f, |
35 | -0x1.a74172p-9f, |
36 | -0x1.cb694cp-9f, |
37 | // EXP10M1F_EXCEPTS_HI |
38 | 0x1.8d31eep-8f, |
39 | 0x1.915fcep-8f, |
40 | 0x1.bcf982p-8f, |
41 | 0x1.99ff0ap-7f, |
42 | 0x1.75ea14p-6f, |
43 | 0x1.f81b64p-6f, |
44 | 0x1.fafecp+3f, |
45 | -0x1.3bf094p-8f, |
46 | -0x1.4558bcp-8f, |
47 | -0x1.4bb43p-8f, |
48 | -0x1.776cc8p-8f, |
49 | -0x1.f024cp-8f, |
50 | -0x1.f510eep-8f, |
51 | -0x1.0b43c4p-7f, |
52 | -0x1.245ee4p-7f, |
53 | -0x1.f9f2dap-7f, |
54 | -0x1.08e42p-6f, |
55 | -0x1.0cdc44p-5f, |
56 | -0x1.ca4322p-5f, |
57 | // Exceptional integers. |
58 | 8.0f, |
59 | 9.0f, |
60 | 10.0f, |
61 | // Overflow boundaries. |
62 | 0x1.344134p+5f, |
63 | 0x1.344136p+5f, |
64 | 0x1.344138p+5f, |
65 | // Underflow boundaries. |
66 | -0x1.e1a5e0p+2f, |
67 | -0x1.e1a5e2p+2f, |
68 | -0x1.e1a5e4p+2f, |
69 | }; |
70 | |
71 | for (float x : INPUTS) { |
72 | libc_errno = 0; |
73 | EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10m1, x, |
74 | LIBC_NAMESPACE::exp10m1f(x), 0.5); |
75 | } |
76 | } |
77 | |
78 | TEST_F(LlvmLibcExp10m1fTest, InFloatRange) { |
79 | constexpr uint32_t COUNT = 100'000; |
80 | constexpr uint32_t STEP = UINT32_MAX / COUNT; |
81 | for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) { |
82 | float x = FPBits(v).get_val(); |
83 | if (FPBits(v).is_inf_or_nan()) |
84 | continue; |
85 | libc_errno = 0; |
86 | float result = LIBC_NAMESPACE::exp10m1f(x); |
87 | |
88 | // If the computation resulted in an error or did not produce valid result |
89 | // in the single-precision floating point range, then ignore comparing with |
90 | // MPFR result as MPFR can still produce valid results because of its |
91 | // wider precision. |
92 | if (FPBits(result).is_inf_or_nan() || libc_errno != 0) |
93 | continue; |
94 | ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10m1, x, |
95 | LIBC_NAMESPACE::exp10m1f(x), 0.5); |
96 | } |
97 | } |
98 | |