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