diff options
Diffstat (limited to 'libc/test/src/math/TruncTest.h')
-rw-r--r-- | libc/test/src/math/TruncTest.h | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libc/test/src/math/TruncTest.h b/libc/test/src/math/TruncTest.h index bc5b761..76c9740 100644 --- a/libc/test/src/math/TruncTest.h +++ b/libc/test/src/math/TruncTest.h @@ -9,6 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_TRUNCTEST_H #define LLVM_LIBC_TEST_SRC_MATH_TRUNCTEST_H +#include "src/__support/CPP/algorithm.h" #include "test/UnitTest/FEnvSafeTest.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -62,18 +63,21 @@ public: EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); EXPECT_FP_EQ(T(10.0), func(T(10.65))); EXPECT_FP_EQ(T(-10.0), func(T(-10.65))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.96))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96))); + EXPECT_FP_EQ(T(123.0), func(T(123.38))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.38))); + EXPECT_FP_EQ(T(123.0), func(T(123.96))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.96))); } void testRange(TruncFunc func) { - constexpr StorageType COUNT = 100'000; - constexpr StorageType STEP = STORAGE_MAX / COUNT; - for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) { - T x = FPBits(v).get_val(); - if (isnan(x) || isinf(x)) + constexpr int COUNT = 100'000; + constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max( + static_cast<StorageType>(STORAGE_MAX / COUNT), StorageType(1)); + StorageType v = 0; + for (int i = 0; i <= COUNT; ++i, v += STEP) { + FPBits xbits(v); + T x = xbits.get_val(); + if (xbits.is_inf_or_nan()) continue; ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, func(x), 0.0); |