11 #include <boost/test/unit_test.hpp>
20 uint64_t TestDouble(
double f) {
41 BOOST_CHECK_EQUAL(TestDouble(std::numeric_limits<double>::infinity()), 0x7ff0000000000000U);
42 BOOST_CHECK_EQUAL(TestDouble(-std::numeric_limits<double>::infinity()), 0xfff0000000000000);
50 if (std::numeric_limits<double>::is_iec559) {
54 TestDouble(std::numeric_limits<double>::min());
55 TestDouble(-std::numeric_limits<double>::min());
56 TestDouble(std::numeric_limits<double>::max());
57 TestDouble(-std::numeric_limits<double>::max());
58 TestDouble(std::numeric_limits<double>::lowest());
59 TestDouble(-std::numeric_limits<double>::lowest());
60 TestDouble(std::numeric_limits<double>::quiet_NaN());
61 TestDouble(-std::numeric_limits<double>::quiet_NaN());
62 TestDouble(std::numeric_limits<double>::signaling_NaN());
63 TestDouble(-std::numeric_limits<double>::signaling_NaN());
64 TestDouble(std::numeric_limits<double>::denorm_min());
65 TestDouble(-std::numeric_limits<double>::denorm_min());
68 for (
int j = 0; j < 1000; ++j) {
72 for (
int x = 0; x < 512; ++x) {
74 v &= ~(uint64_t{1} << 0);
75 if (x & 1) v |= (uint64_t{1} << 0);
76 v &= ~(uint64_t{1} << 1);
77 if (x & 2) v |= (uint64_t{1} << 1);
78 v &= ~(uint64_t{1} << 50);
79 if (x & 4) v |= (uint64_t{1} << 50);
80 v &= ~(uint64_t{1} << 51);
81 if (x & 8) v |= (uint64_t{1} << 51);
82 v &= ~(uint64_t{1} << 52);
83 if (x & 16) v |= (uint64_t{1} << 52);
84 v &= ~(uint64_t{1} << 53);
85 if (x & 32) v |= (uint64_t{1} << 53);
86 v &= ~(uint64_t{1} << 61);
87 if (x & 64) v |= (uint64_t{1} << 61);
88 v &= ~(uint64_t{1} << 62);
89 if (x & 128) v |= (uint64_t{1} << 62);
90 v &= ~(uint64_t{1} << 63);
91 if (x & 256) v |= (uint64_t{1} << 63);
94 uint64_t v2 = TestDouble(f);
116 for (
int i = 0; i < 1000; i++) {
122 for (
int i = 0; i < 1000; i++) {
126 BOOST_CHECK_MESSAGE(i == j,
"decoded:" << j <<
" expected:" << i);
Double ended buffer combining vector and stream-like interfaces.
BOOST_AUTO_TEST_SUITE_END()
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
uint64_t EncodeDouble(double f) noexcept
double DecodeDouble(uint64_t v) noexcept
BOOST_AUTO_TEST_CASE(double_serfloat_tests)
static uint64_t InsecureRandBits(int bits)
uint256 uint256S(const char *str)