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

Roundtrip failure for double -0x1.e42427b42cb42p+949 #1183

Closed
pauldreik opened this issue Jul 19, 2024 · 2 comments · Fixed by #1192
Closed

Roundtrip failure for double -0x1.e42427b42cb42p+949 #1183

pauldreik opened this issue Jul 19, 2024 · 2 comments · Fixed by #1192
Labels
bug Something isn't working

Comments

@pauldreik
Copy link
Contributor

According to the FAQ, numbers should be roundtrippable:
https://github.com/stephenberry/glaze/blob/main/docs/FAQ.md#is-the-writeread-api-deterministic

Here is an example which seems to be 1 ULP off for all three numbers:

struct D { double value;};

"double roundtrip"_test = [] {
       for (const double expected:{
            -0x1.e42427b42cb42p+949,
           -0x1.3ffff0d0ddb37p+725,
           0x1.73d40c08b20ffp-395
   }) {
           const D d{expected};
           auto str = glz::write_json(d).value_or(std::string{});
           auto restored = glz::read_json<D>(str);
           expect(restored.has_value());
           expect(restored.value().value == d.value);

       }
   };

The first value is https://float.exposed/0xfb4e42427b42cb42 and does not seem to be extreme (close to subnormal, max, min etc).

Side question: I could not put struct D inside the function (to narrow the scope where it is visible). Is that expected?

@stephenberry stephenberry added the bug Something isn't working label Jul 19, 2024
@stephenberry
Copy link
Owner

Side question: I could not put struct D inside the function (to narrow the scope where it is visible). Is that expected?

Yes, this is expected behavior with the unit test framework and the current pure reflection mechanisms. It is not a limitation typically encountered in software.

@stephenberry stephenberry linked a pull request Jul 21, 2024 that will close this issue
@stephenberry
Copy link
Owner

These 1 ULP errors have been fixed with the merge of #1192

@pauldreik pauldreik mentioned this issue Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants