summaryrefslogtreecommitdiff
path: root/libc/test/src/math/RoundToIntegerTest.h
diff options
context:
space:
mode:
Diffstat (limited to 'libc/test/src/math/RoundToIntegerTest.h')
-rw-r--r--libc/test/src/math/RoundToIntegerTest.h29
1 files changed, 20 insertions, 9 deletions
diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h
index d40e15080087..bb7e8643973c 100644
--- a/libc/test/src/math/RoundToIntegerTest.h
+++ b/libc/test/src/math/RoundToIntegerTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FEnvSafeTest.h"
@@ -136,10 +137,13 @@ public:
return;
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
+ constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
+ if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
+ return;
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
- bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
+ bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
bits.set_sign(Sign::NEG);
bits.set_mantissa(0);
@@ -200,10 +204,13 @@ public:
return;
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
+ constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
+ if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
+ return;
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
- bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
+ bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
bits.set_sign(Sign::NEG);
bits.set_mantissa(FPBits::FRACTION_MASK);
@@ -226,8 +233,10 @@ public:
}
void testSubnormalRange(RoundToIntegerFunc func) {
- constexpr StorageType COUNT = 1'000'001;
- constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
+ constexpr int COUNT = 1'000'001;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
+ StorageType(1));
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
F x = FPBits(i).get_val();
if (x == F(0.0))
@@ -268,15 +277,17 @@ public:
if (sizeof(I) > sizeof(long))
return;
- constexpr StorageType COUNT = 1'000'001;
- constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
+ constexpr int COUNT = 1'000'001;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
+ StorageType(1));
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
- F x = FPBits(i).get_val();
+ FPBits xbits(i);
+ F x = xbits.get_val();
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
- if (isnan(x)) {
+ if (xbits.is_nan())
continue;
- }
if (TestModes) {
for (int m : ROUNDING_MODES) {