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

accept numbers with large exponent #892

Merged
merged 2 commits into from
Jun 28, 2023

Conversation

grisumbras
Copy link
Member

This changes treatment of numbers with exponents larger than INT_MAX. The current behaviour is somewhat arbitrary: we reject numbers with exponents that do not fit into INT_MAX, but we accept numbers with exponents that do not fit in double (we parse those numbers as infinity).

This PR removes the inconsistency by just setting exponent to INT_MAX. The alternative solution to inconsistency -- making it an error if the exponent doesn't fit into double is undesirable. Parsing such numbers as infinity/zero is actually standard practice.

@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #892 (3d751ad) into develop (6a034f2) will decrease coverage by 0.02%.
The diff coverage is 88.23%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #892      +/-   ##
===========================================
- Coverage    92.99%   92.97%   -0.02%     
===========================================
  Files           85       85              
  Lines         8061     8072      +11     
===========================================
+ Hits          7496     7505       +9     
- Misses         565      567       +2     
Impacted Files Coverage Δ
include/boost/json/basic_parser_impl.hpp 98.44% <88.23%> (-0.15%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a034f2...3d751ad. Read the comment docs.

@pdimov
Copy link
Member

pdimov commented May 19, 2023

This will theoretically fail for numbers like 0.000....0001e2147483648 where the number of zeroes is close to 2147483647, but I suppose this can never happen in practice.

Does TEST_GOOD check that the parsed value is zero or infinity in these cases?

@cppalliance-bot
Copy link

@grisumbras
Copy link
Member Author

Does TEST_GOOD check that the parsed value is zero or infinity in these cases?

No, it only tests that parse doesn't result in an error.

@grisumbras
Copy link
Member Author

This will theoretically fail for numbers like 0.000....0001e2147483648 where the number of zeroes is close to 2147483647, but I suppose this can never happen in practice.

Maybe we should consider such numbers errors instead (as far as I can see, we don't even check for overflow of the corresponding variable at the moment).

@pdimov
Copy link
Member

pdimov commented May 19, 2023

Considering them errors should be fine.

@cppalliance-bot
Copy link

@cppalliance-bot
Copy link

@cppalliance-bot
Copy link

@grisumbras grisumbras merged commit 3d751ad into boostorg:develop Jun 28, 2023
2 of 4 checks passed
@grisumbras grisumbras deleted the fix/inconsistent-exponent branch June 28, 2023 11:00
@cppalliance-bot
Copy link

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