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

MONGOCRYPT-712 Improve double handling with precision #869

Merged
merged 8 commits into from
Jul 26, 2024

Conversation

markbenvenuto
Copy link
Collaborator

Min and max integer of a double is -2^53 and 2^53. Remember double has a separate sign bit unlike integers. Javascript's Number constants are not correct for doubles.

Depends on Shreyas' change to compute the right max value.

test/test-mc-range-encoding.c Outdated Show resolved Hide resolved
.precision = OPT_U32_C(0),
.expect = 9007199254740996,
.expectMax = OPT_U64_C(36028797018963967)},
{.value = 5,
Copy link
Collaborator

Choose a reason for hiding this comment

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

After thinking this through a bit more, although we know that this is probably correct, we still need a few more test cases. We basically need to show that the imprecision that we see in the range [2^53 < abs(n) < 2^63] does not impact the precision in the range of [-(2^53) < val < 2^53]. To make that happen, we should probably run a few test cases.

We should test some random bounds where min E [-2^53, -2^54, -2^55, ... -2^63] and max E [2^53, 2^54, 2^55, ... 2^63] and show that when value = [0, 1, 2, 3, 4, 5], we have .expect = [max + value].

I know that we've poured over the math, but I still have some qualms about us possibly losing precision here. I also have some general qualms about floating point imprecision in a fractional number, but I am not sure that those will ever really go away :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doubles lose precision for their significant between 2^52 and 2^63. The lose precision at 2^(i-52) where i = bits. I generated test cases from the server code and added a few more test cases. One for each number between 52-62 with values from 0-4. I did not add 40 tests, just 10 because 40 would be a waste.

Copy link
Collaborator

@shreyaskalyan shreyaskalyan left a comment

Choose a reason for hiding this comment

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

If my comment makes sense, please do incorporate it. I mean for it to be more of a discussion rather than a prescription.

Base automatically changed from shreyaskalyan/MONGOCRYPT-702 to master July 24, 2024 19:43
Copy link
Collaborator

@shreyaskalyan shreyaskalyan left a comment

Choose a reason for hiding this comment

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

Took another pass - LGTM stands

@markbenvenuto markbenvenuto merged commit 3fd7377 into master Jul 26, 2024
56 of 59 checks passed
@markbenvenuto markbenvenuto deleted the markbenvenuto/mongocrypt-712 branch July 26, 2024 15:23
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.

3 participants