Repository navigation
Fix parse_f64_approx returning NaN for 0e400 - #991
Open
Sebastian Turner (auraseb) wants to merge 1 commit into
Open
Sebastian Turner (auraseb) wants to merge 1 commit into
Sebastian Turner (auraseb) wants to merge 1 commit into
Conversation
Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parse_f64_approxscaled a zero mantissa by10^exponent. For exponents above about 308 that is0 * inf, so0e400parsed asNaNinstead of0.0, and the JSON parser then rejected it as invalid. A zero mantissa now skips the scaling, which also keeps the sign of-0e400.The exponent saturates at
i32::MAX, but the table index then usedexponent + 3, which panicked with an overflow in debug builds for inputs like1e2147483645. The index now useswrapping_add, so such inputs fall through topowiand return infinity, as in release builds.Tests: added
zero_with_large_exponentandhuge_exponenttofloat.rsand a0e400case to the JSON number test. All three fail on main and pass with this change.cargo test --workspace,cargo fmt --checkandcargo clippy --all-targets -- --deny warningspass.Fixes #990