-
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
Changes from 3 commits
6f0683b
68acf21
3b405fc
d5c837b
d59e1d7
05de839
33ff3a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
pack_imp_uint64(uint64_t(d)); | ||||||
return *this; | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please erase empty line above. |
||||||
} 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
pack_imp_int64(int64_t(d)); | ||||||
return *this; | ||||||
} | ||||||
} | ||||||
|
||||||
union { float f; uint32_t i; } mem; | ||||||
mem.f = d; | ||||||
char buf[5]; | ||||||
|
@@ -1149,6 +1161,18 @@ 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::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 commentThe reason will be displayed to describe this comment to others. Learn more. Please apply the same fix as float. |
||||||
union { double f; uint64_t i; } mem; | ||||||
mem.f = d; | ||||||
char buf[9]; | ||||||
|
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.