mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-06-25 22:15:23 +02:00
update msgpack_basic test for compact double packaging
update pack_double and pack_float to avoid warnings
This commit is contained in:
parent
d5c837b612
commit
d59e1d7716
@ -1140,10 +1140,10 @@ inline packer<Stream>& packer<Stream>::pack_float(float d)
|
||||
{
|
||||
if(d == d) { // check for nan
|
||||
// compare d to limits to avoid undefined behaviour
|
||||
if(d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) {
|
||||
if(d >= 0 && d <= float(std::numeric_limits<uint64_t>::max()) && d == float(uint64_t(d))) {
|
||||
pack_imp_uint64(uint64_t(d));
|
||||
return *this;
|
||||
} else if(d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) {
|
||||
} else if(d >= float(std::numeric_limits<int64_t>::min()) && d == float(int64_t(d))) {
|
||||
pack_imp_int64(int64_t(d));
|
||||
return *this;
|
||||
}
|
||||
@ -1162,10 +1162,10 @@ inline packer<Stream>& packer<Stream>::pack_double(double d)
|
||||
{
|
||||
if(d == d) { // check for nan
|
||||
// compare d to limits to avoid undefined behaviour
|
||||
if(d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) {
|
||||
if(d >= 0 && d <= double(std::numeric_limits<uint64_t>::max()) && d == double(uint64_t(d))) {
|
||||
pack_imp_uint64(uint64_t(d));
|
||||
return *this;
|
||||
} else if(d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) {
|
||||
} else if(d >= double(std::numeric_limits<int64_t>::min()) && d == double(int64_t(d))) {
|
||||
pack_imp_int64(int64_t(d));
|
||||
return *this;
|
||||
}
|
||||
|
@ -154,6 +154,8 @@ BOOST_AUTO_TEST_CASE(simple_buffer_float)
|
||||
v.push_back(-0.0);
|
||||
v.push_back(1.0);
|
||||
v.push_back(-1.0);
|
||||
v.push_back(1.1f);
|
||||
v.push_back(-1.1f);
|
||||
v.push_back(numeric_limits<float>::min());
|
||||
v.push_back(numeric_limits<float>::max());
|
||||
v.push_back(nanf("tag"));
|
||||
@ -186,6 +188,12 @@ BOOST_AUTO_TEST_CASE(simple_buffer_float)
|
||||
BOOST_CHECK(std::isinf(val2));
|
||||
else
|
||||
BOOST_CHECK(fabs(val2 - val1) <= kEPS);
|
||||
|
||||
// check for compact storing of float
|
||||
if (val1 == val1 && val1 == float(int64_t(val1)))
|
||||
BOOST_REQUIRE_EQUAL(sbuf.size(),1);
|
||||
else
|
||||
BOOST_REQUIRE_EQUAL(sbuf.data()[0],char(0xca));
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,6 +244,8 @@ BOOST_AUTO_TEST_CASE(simple_buffer_double)
|
||||
v.push_back(-0.0);
|
||||
v.push_back(1.0);
|
||||
v.push_back(-1.0);
|
||||
v.push_back(1.1);
|
||||
v.push_back(-1.1);
|
||||
v.push_back(numeric_limits<double>::min());
|
||||
v.push_back(numeric_limits<double>::max());
|
||||
v.push_back(nanf("tag"));
|
||||
@ -272,6 +282,12 @@ BOOST_AUTO_TEST_CASE(simple_buffer_double)
|
||||
BOOST_CHECK(std::isinf(val2));
|
||||
else
|
||||
BOOST_CHECK(fabs(val2 - val1) <= kEPS);
|
||||
|
||||
// check for compact storing of double
|
||||
if (val1 == val1 && val1 == double(int64_t(val1)))
|
||||
BOOST_REQUIRE_EQUAL(sbuf.size(),1);
|
||||
else
|
||||
BOOST_REQUIRE_EQUAL(uint8_t(sbuf.data()[0]),uint8_t(0xcb));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user