0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

serfloat: do not test encode(bits)=bits anymore

This commit is contained in:
Pieter Wuille 2024-01-05 14:26:52 -05:00
parent bdddf364c9
commit b45f1f5658

View file

@ -47,7 +47,6 @@ BOOST_AUTO_TEST_CASE(double_serfloat_tests) {
BOOST_CHECK_EQUAL(TestDouble(4.0), 0x4010000000000000ULL); BOOST_CHECK_EQUAL(TestDouble(4.0), 0x4010000000000000ULL);
BOOST_CHECK_EQUAL(TestDouble(785.066650390625), 0x4088888880000000ULL); BOOST_CHECK_EQUAL(TestDouble(785.066650390625), 0x4088888880000000ULL);
// Roundtrip test on IEC559-compatible systems
if (std::numeric_limits<double>::is_iec559) { if (std::numeric_limits<double>::is_iec559) {
BOOST_CHECK_EQUAL(sizeof(double), 8U); BOOST_CHECK_EQUAL(sizeof(double), 8U);
BOOST_CHECK_EQUAL(sizeof(uint64_t), 8U); BOOST_CHECK_EQUAL(sizeof(uint64_t), 8U);
@ -64,8 +63,7 @@ BOOST_AUTO_TEST_CASE(double_serfloat_tests) {
TestDouble(-std::numeric_limits<double>::signaling_NaN()); TestDouble(-std::numeric_limits<double>::signaling_NaN());
TestDouble(std::numeric_limits<double>::denorm_min()); TestDouble(std::numeric_limits<double>::denorm_min());
TestDouble(-std::numeric_limits<double>::denorm_min()); TestDouble(-std::numeric_limits<double>::denorm_min());
// Test exact encoding: on currently supported platforms, EncodeDouble // On IEC559-compatible systems, construct doubles to test from the encoding.
// should produce exactly the same as the in-memory representation for non-NaN.
for (int j = 0; j < 1000; ++j) { for (int j = 0; j < 1000; ++j) {
// Iterate over 9 specific bits exhaustively; the others are chosen randomly. // Iterate over 9 specific bits exhaustively; the others are chosen randomly.
// These specific bits are the sign bit, and the 2 top and bottom bits of // These specific bits are the sign bit, and the 2 top and bottom bits of
@ -92,8 +90,7 @@ BOOST_AUTO_TEST_CASE(double_serfloat_tests) {
if (x & 256) v |= (uint64_t{1} << 63); if (x & 256) v |= (uint64_t{1} << 63);
double f; double f;
memcpy(&f, &v, 8); memcpy(&f, &v, 8);
uint64_t v2 = TestDouble(f); TestDouble(f);
if (!std::isnan(f)) BOOST_CHECK_EQUAL(v, v2);
} }
} }
} }