Skip to content
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

Merged
merged 7 commits into from
Jun 13, 2022

Conversation

GeorgFritze
Copy link

@GeorgFritze GeorgFritze commented May 13, 2022

PR for issue #1017

Copy link
Contributor

@redboltz redboltz left a 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.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (d == d) { // check for nan
if(d == d) { // check for nan

@@ -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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)) {

if (d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) {
pack_imp_uint64(uint64_t(d));
return *this;

Copy link
Contributor

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.

pack_imp_uint64(uint64_t(d));
return *this;

} else if (d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} 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)) {

Comment on lines 1164 to 1175
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;
}
}

Copy link
Contributor

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.

@redboltz
Copy link
Contributor

redboltz commented Jun 5, 2022

It seems that CI reports warnings (as errors). Could you fix this?

/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:[114](https://github.com/msgpack/msgpack-c/runs/6744024570?check_suite_focus=true#step:8:115)3:27: error: implicit conversion from 'unsigned long' to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        if(d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) {
                       ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:1143:72: error: implicit conversion from 'uint64_t' (aka 'unsigned long') to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        if(d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) {
                                                                    ~~ ^~~~~~~~~~~
/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:1146:24: error: implicit conversion from 'long' to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        } else if(d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) {
                    ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:1146:68: error: implicit conversion from 'int64_t' (aka 'long') to 'float' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        } else if(d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) {
                                                                ~~ ^~~~~~~~~~
/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:[116](https://github.com/msgpack/msgpack-c/runs/6744024570?check_suite_focus=true#step:8:117)5:27: error: implicit conversion from 'unsigned long' to 'double' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        if(d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) {
                       ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:1165:72: error: implicit conversion from 'uint64_t' (aka 'unsigned long') to 'double' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        if(d >= 0 && d <= std::numeric_limits<uint64_t>::max() && d == uint64_t(d)) {
                                                                    ~~ ^~~~~~~~~~~
/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:1168:24: error: implicit conversion from 'long' to 'double' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        } else if(d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) {
                    ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/msgpack-c/msgpack-c/include/msgpack/v1/pack.hpp:1168:68: error: implicit conversion from 'int64_t' (aka 'long') to 'double' may lose precision [-Werror,-Wimplicit-int-float-conversion]
        } else if(d >= std::numeric_limits<int64_t>::min() && d == int64_t(d)) {

@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2022

Codecov Report

Merging #1018 (05de839) into cpp_master (05f654f) will increase coverage by 0.04%.
The diff coverage is 100.00%.

❗ Current head 05de839 differs from pull request most recent head 33ff3a4. Consider uploading reports for the commit 33ff3a4 to get more accurate results

@@              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              

@redboltz
Copy link
Contributor

Thank you for updating. Great work!

@redboltz redboltz merged commit d13d933 into msgpack:cpp_master Jun 13, 2022
speleo3 added a commit to speleo3/mmtf-c that referenced this pull request Oct 6, 2022
Floats may be stored as integers, and msgpack-cpp does that proactively
since version 4.1.2, see msgpack/msgpack-c#1018
speleo3 added a commit to speleo3/pymol-open-source that referenced this pull request Oct 6, 2022
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
JarrettSJohnson pushed a commit to schrodinger/pymol-open-source that referenced this pull request Oct 6, 2022
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
StevenMaude added a commit to sensiblecodeio/pdf2msgpack that referenced this pull request Aug 4, 2023
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
speleo3 added a commit to rcsb/mmtf-c that referenced this pull request Sep 26, 2023
Floats may be stored as integers, and msgpack-cpp does that proactively
since version 4.1.2, see msgpack/msgpack-c#1018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants