|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 | #include "src/__support/CPP/type_traits.h"
|
| 9 | +#include "src/__support/FPUtil/FPBits.h" |
| 10 | +#include "src/__support/FPUtil/ManipulationFunctions.h" // ldexp |
9 | 11 | #include "src/__support/FPUtil/generic/FMod.h"
|
10 | 12 | #include "test/UnitTest/FPMatcher.h"
|
11 | 13 | #include "test/UnitTest/Test.h"
|
12 | 14 | #include "utils/MPFRWrapper/MPFRUtils.h"
|
13 | 15 |
|
14 | 16 | #include <array>
|
15 |
| -#include <cmath> |
16 |
| -#include <limits> |
17 | 17 |
|
18 | 18 | namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
|
19 | 19 |
|
20 | 20 | template <typename T, bool InverseMultiplication>
|
21 | 21 | class LlvmLibcFModTest : public LIBC_NAMESPACE::testing::Test {
|
22 | 22 |
|
23 |
| - using U = typename LIBC_NAMESPACE::fputil::FPBits<T>::StorageType; |
| 23 | + using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>; |
| 24 | + using U = typename FPBits::StorageType; |
24 | 25 | using DivisionHelper = LIBC_NAMESPACE::cpp::conditional_t<
|
25 | 26 | InverseMultiplication,
|
26 | 27 | LIBC_NAMESPACE::fputil::generic::FModDivisionInvMultHelper<U>,
|
27 | 28 | LIBC_NAMESPACE::fputil::generic::FModDivisionSimpleHelper<U>>;
|
28 | 29 |
|
29 |
| - static constexpr std::array<T, 11> test_bases = { |
| 30 | + static constexpr std::array<T, 11> TEST_BASES = { |
30 | 31 | T(0.0),
|
31 | 32 | T(1.0),
|
32 | 33 | T(3.0),
|
33 | 34 | T(27.0),
|
34 | 35 | T(11.0 / 8.0),
|
35 | 36 | T(2.764443),
|
36 |
| - T(1.0) - std::numeric_limits<T>::epsilon(), |
37 |
| - T(1.0) + std::numeric_limits<T>::epsilon(), |
38 |
| - T(M_PI), |
39 |
| - T(M_SQRT2), |
40 |
| - T(M_E), |
41 |
| - }; |
| 37 | + T(1.0) - T(0x1.0p-23) - T(0x1.0p-52) - T(0x1.0p-112), |
| 38 | + T(1.0) + T(0x1.0p-23) + T(0x1.0p-52) + T(0x1.0p-112), |
| 39 | + T(3.14159265), |
| 40 | + T(1.41421356), |
| 41 | + T(2.71828183)}; |
42 | 42 |
|
43 | 43 | public:
|
44 | 44 | void testExtensive() {
|
45 | 45 | using FMod = LIBC_NAMESPACE::fputil::generic::FMod<T, U, DivisionHelper>;
|
46 |
| - using nl = std::numeric_limits<T>; |
47 |
| - int min2 = nl::min_exponent - nl::digits - 5; |
48 |
| - int max2 = nl::max_exponent + 3; |
49 |
| - for (T by : test_bases) { |
| 46 | + int min2 = -(FPBits::MAX_BIASED_EXPONENT + FPBits::SIG_LEN) / 2; |
| 47 | + int max2 = 3 + FPBits::MAX_BIASED_EXPONENT / 2; |
| 48 | + for (T by : TEST_BASES) { |
50 | 49 | for (int iy = min2; iy < max2; iy++) {
|
51 |
| - T y = by * std::ldexp(2, iy); |
52 |
| - if (y == 0 || !std::isfinite(y)) |
| 50 | + T y = by * LIBC_NAMESPACE::fputil::ldexp(2.0, iy); |
| 51 | + FPBits y_bits(y); |
| 52 | + if (y_bits.is_zero() || !y_bits.is_finite()) |
53 | 53 | continue;
|
54 |
| - for (T bx : test_bases) { |
| 54 | + for (T bx : TEST_BASES) { |
55 | 55 | for (int ix = min2; ix < max2; ix++) {
|
56 |
| - T x = bx * std::ldexp(2, ix); |
57 |
| - if (!std::isfinite(x)) |
| 56 | + T x = bx * LIBC_NAMESPACE::fputil::ldexp(2.0, ix); |
| 57 | + if (!FPBits(x).is_finite()) |
58 | 58 | continue;
|
59 | 59 | T result = FMod::eval(x, y);
|
60 | 60 | mpfr::BinaryInput<T> input{x, y};
|
|
0 commit comments