-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pack double and float more size efficient #1018
Conversation
check also for nan and numeric limits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I commented some coding stype issue. Please fix them.
include/msgpack/v1/pack.hpp
Outdated
@@ -1138,6 +1138,18 @@ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (d == d) { // check for nan | |
if(d == d) { // check for nan |
include/msgpack/v1/pack.hpp
Outdated
@@ -1138,6 +1138,18 @@ 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::max() to avoid undefined behaviour | |||
if (d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) { | |
if(d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) { |
include/msgpack/v1/pack.hpp
Outdated
if (d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) { | ||
pack_imp_uint64(uint64_t(d)); | ||
return *this; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please erase empty line above.
include/msgpack/v1/pack.hpp
Outdated
pack_imp_uint64(uint64_t(d)); | ||
return *this; | ||
|
||
} else if (d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) { | |
} else if(d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) { |
include/msgpack/v1/pack.hpp
Outdated
if (d == d) { // check for nan | ||
// compare d to limits::max() to avoid undefined behaviour | ||
if (d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) { | ||
pack_imp_uint64(uint64_t(d)); | ||
return *this; | ||
|
||
} else if (d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) { | ||
pack_imp_int64(int64_t(d)); | ||
return *this; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply the same fix as float.
It seems that CI reports warnings (as errors). Could you fix this?
|
Codecov Report
@@ Coverage Diff @@
## cpp_master #1018 +/- ##
==============================================
+ Coverage 85.56% 85.60% +0.04%
==============================================
Files 79 79
Lines 5009 5023 +14
==============================================
+ Hits 4286 4300 +14
Misses 723 723 |
update pack_double and pack_float to avoid warnings
Thank you for updating. Great work! |
Floats may be stored as integers, and msgpack-cpp does that proactively since version 4.1.2, see msgpack/msgpack-c#1018
Floats may be stored as integers in msgpack, and msgpack-cpp does that proactively since version 4.1.2. That broke the `unitCell` angle round trip in `testSave_symmetry__mmtf`. See also: rcsb/mmtf-c#35 msgpack/msgpack-c#1018
Floats may be stored as integers in msgpack, and msgpack-cpp does that proactively since version 4.1.2. That broke the `unitCell` angle round trip in `testSave_symmetry__mmtf`. See also: rcsb/mmtf-c#35 msgpack/msgpack-c#1018
This is v4.1.1 We can't update beyond v4.1.1 because of what is a breaking change for pdf2msgpack: msgpack/msgpack-c#1018
Floats may be stored as integers, and msgpack-cpp does that proactively since version 4.1.2, see msgpack/msgpack-c#1018
Revert "Merge pull request #1018 from GeorgFritze/cpp_master"
PR for issue #1017