Skip to content

Commit

Permalink
Merge pull request #1144 from stephanlachnit/p-cpp-revert-broken-float
Browse files Browse the repository at this point in the history
Revert "Merge pull request #1018 from GeorgFritze/cpp_master"
  • Loading branch information
redboltz authored Oct 31, 2024
2 parents 5c606bd + 3788b5b commit 405977d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 38 deletions.
22 changes: 0 additions & 22 deletions include/msgpack/v1/pack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,17 +1138,6 @@ inline packer<Stream>& packer<Stream>::pack_unsigned_long_long(unsigned long lon
template <typename Stream>
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 <= float(std::numeric_limits<uint64_t>::max()) && d == float(uint64_t(d))) {
pack_imp_uint64(uint64_t(d));
return *this;
} else if(d < 0 && d >= float(std::numeric_limits<int64_t>::min()) && d == float(int64_t(d))) {
pack_imp_int64(int64_t(d));
return *this;
}
}

union { float f; uint32_t i; } mem;
mem.f = d;
char buf[5];
Expand All @@ -1160,17 +1149,6 @@ inline packer<Stream>& packer<Stream>::pack_float(float d)
template <typename Stream>
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 <= double(std::numeric_limits<uint64_t>::max()) && d == double(uint64_t(d))) {
pack_imp_uint64(uint64_t(d));
return *this;
} else if(d < 0 && d >= double(std::numeric_limits<int64_t>::min()) && d == double(int64_t(d))) {
pack_imp_int64(int64_t(d));
return *this;
}
}

union { double f; uint64_t i; } mem;
mem.f = d;
char buf[9];
Expand Down
16 changes: 0 additions & 16 deletions test/msgpack_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ 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"));
Expand Down Expand Up @@ -188,12 +186,6 @@ 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(std::numeric_limits<int64_t>::min()) && val1 <= float(std::numeric_limits<int64_t>::max()) && val1 == float(int64_t(val1)))
BOOST_REQUIRE_EQUAL(sbuf.size(),1);
else
BOOST_REQUIRE_EQUAL(sbuf.data()[0],char(0xca));
}
}

Expand Down Expand Up @@ -244,8 +236,6 @@ 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"));
Expand Down Expand Up @@ -282,12 +272,6 @@ 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(std::numeric_limits<int64_t>::min()) && val1 <= double(std::numeric_limits<int64_t>::max()) && val1 == double(int64_t(val1)))
BOOST_REQUIRE_EQUAL(sbuf.size(),1);
else
BOOST_REQUIRE_EQUAL(uint8_t(sbuf.data()[0]),uint8_t(0xcb));
}
}

Expand Down

0 comments on commit 405977d

Please sign in to comment.