diff --git a/libc/fuzzing/math/RemQuoDiff.h b/libc/fuzzing/math/RemQuoDiff.h index 84a6a24ce5271..cfb9b7f44e548 100644 --- a/libc/fuzzing/math/RemQuoDiff.h +++ b/libc/fuzzing/math/RemQuoDiff.h @@ -31,21 +31,22 @@ void RemQuoDiff(RemQuoFunc func1, RemQuoFunc func2, const uint8_t *data, T remainder1 = func1(x, y, &q1); T remainder2 = func2(x, y, &q2); - if (isnan(remainder1)) { - if (!isnan(remainder2)) + LIBC_NAMESPACE::fputil::FPBits bits1(remainder1); + LIBC_NAMESPACE::fputil::FPBits bits2(remainder2); + + if (bit1.is_nan()) { + if (!bit2.is_nan()) __builtin_trap(); return; } - if (isinf(remainder2) != isinf(remainder1)) + if (bit1.is_inf() != bit2.is_inf()) __builtin_trap(); // Compare only the 3 LS bits of the quotient. if ((q1 & 0x7) != (q2 & 0x7)) __builtin_trap(); - LIBC_NAMESPACE::fputil::FPBits bits1(remainder1); - LIBC_NAMESPACE::fputil::FPBits bits2(remainder2); if (bits1.uintval() != bits2.uintval()) __builtin_trap(); } diff --git a/libc/fuzzing/stdlib/strtofloat_fuzz.cpp b/libc/fuzzing/stdlib/strtofloat_fuzz.cpp index c158162ba6238..503b55978e2cb 100644 --- a/libc/fuzzing/stdlib/strtofloat_fuzz.cpp +++ b/libc/fuzzing/stdlib/strtofloat_fuzz.cpp @@ -118,9 +118,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { __builtin_trap(); // If any result is NaN, all of them should be NaN. We can't use the usual // comparisons because NaN != NaN. - if (isnan(float_result) ^ isnan(strtof_result)) + if (FPBits(float_result).is_nan() != + FPBits(strtof_result).is_nan()) __builtin_trap(); - if (!isnan(float_result) && float_result != strtof_result) + if (!FPBits(float_result).is_nan() && float_result != strtof_result) __builtin_trap(); mpfr_clear(mpfr_float); } @@ -136,10 +137,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { ptrdiff_t strtod_strlen = out_ptr - str_ptr; if (result_strlen != strtod_strlen) __builtin_trap(); - if (isnan(double_result) ^ isnan(strtod_result) || - isnan(double_result) ^ isnan(atof_result)) + if (FPBits(double_result).is_nan() != + FPBits(strtod_result).is_nan() || + FPBits(double_result).is_nan() != + FPBits(atof_result).is_nan()) __builtin_trap(); - if (!isnan(double_result) && + if (!FPBits(double_result).is_nan() && (double_result != strtod_result || double_result != atof_result)) __builtin_trap(); mpfr_clear(mpfr_double); @@ -156,9 +159,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { ptrdiff_t strtold_strlen = out_ptr - str_ptr; if (result_strlen != strtold_strlen) __builtin_trap(); - if (isnan(long_double_result) ^ isnan(strtold_result)) + if (FPBits(long_double_result).is_nan() ^ + FPBits(strtold_result).is_nan()) __builtin_trap(); - if (!isnan(long_double_result) && long_double_result != strtold_result) + if (!FPBits(long_double_result).is_nan() && + long_double_result != strtold_result) __builtin_trap(); mpfr_clear(mpfr_long_double); } diff --git a/libc/test/src/math/cbrt_test.cpp b/libc/test/src/math/cbrt_test.cpp index 123351496118b..2ef2140966f52 100644 --- a/libc/test/src/math/cbrt_test.cpp +++ b/libc/test/src/math/cbrt_test.cpp @@ -21,8 +21,8 @@ using LIBC_NAMESPACE::testing::tlog; TEST_F(LlvmLibcCbrtTest, InDoubleRange) { constexpr uint64_t COUNT = 123'451; - uint64_t START = LIBC_NAMESPACE::fputil::FPBits(1.0).uintval(); - uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits(8.0).uintval(); + uint64_t START = FPBits(1.0).uintval(); + uint64_t STOP = FPBits(8.0).uintval(); uint64_t STEP = (STOP - START) / COUNT; auto test = [&](mpfr::RoundingMode rounding_mode) { @@ -38,12 +38,12 @@ TEST_F(LlvmLibcCbrtTest, InDoubleRange) { for (uint64_t i = 0, v = START; i <= COUNT; ++i, v += STEP) { double x = FPBits(v).get_val(); - if (isnan(x) || isinf(x)) + if (FPBits(x).is_inf_or_nan()) continue; double result = LIBC_NAMESPACE::cbrt(x); ++total; - if (isnan(result) || isinf(result)) + if (FPBits(result).is_inf_or_nan()) continue; ++tested; diff --git a/libc/test/utils/FPUtil/x86_long_double_test.cpp b/libc/test/utils/FPUtil/x86_long_double_test.cpp index 87796b5c9f5ba..8d16869b2e816 100644 --- a/libc/test/utils/FPUtil/x86_long_double_test.cpp +++ b/libc/test/utils/FPUtil/x86_long_double_test.cpp @@ -27,8 +27,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) { // If exponent has the max value and the implicit bit is 0, // then the number is a NaN for all values of mantissa. bits.set_mantissa(i); - long double nan = bits.get_val(); - ASSERT_NE(static_cast(isnan(nan)), 0); ASSERT_TRUE(bits.is_nan()); } @@ -38,8 +36,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) { // then the number is a NaN for all non-zero values of mantissa. // Note the initial value of |i| of 1 to avoid a zero mantissa. bits.set_mantissa(i); - long double nan = bits.get_val(); - ASSERT_NE(static_cast(isnan(nan)), 0); ASSERT_TRUE(bits.is_nan()); } @@ -49,8 +45,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) { // If exponent is non-zero and also not max, and the implicit bit is 0, // then the number is a NaN for all values of mantissa. bits.set_mantissa(i); - long double nan = bits.get_val(); - ASSERT_NE(static_cast(isnan(nan)), 0); ASSERT_TRUE(bits.is_nan()); } @@ -60,8 +54,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) { // If exponent is non-zero and also not max, and the implicit bit is 1, // then the number is normal value for all values of mantissa. bits.set_mantissa(i); - long double valid = bits.get_val(); - ASSERT_EQ(static_cast(isnan(valid)), 0); ASSERT_FALSE(bits.is_nan()); } @@ -70,8 +62,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) { for (unsigned int i = 0; i < COUNT; ++i) { // If exponent is zero, then the number is a valid but denormal value. bits.set_mantissa(i); - long double valid = bits.get_val(); - ASSERT_EQ(static_cast(isnan(valid)), 0); ASSERT_FALSE(bits.is_nan()); } @@ -80,8 +70,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) { for (unsigned int i = 0; i < COUNT; ++i) { // If exponent is zero, then the number is a valid but denormal value. bits.set_mantissa(i); - long double valid = bits.get_val(); - ASSERT_EQ(static_cast(isnan(valid)), 0); ASSERT_FALSE(bits.is_nan()); } }