return zero from dec_to_float when the mantissa is zero - #1202
Open
Ramya-9353 wants to merge 1 commit into
Open
Ramya-9353 wants to merge 1 commit into
Ramya-9353 wants to merge 1 commit into
Conversation
|
An automated preview of the documentation is available at https://1202.json.prtest2.cppalliance.org/libs/json/doc/html/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-09-30 17:48:24 UTC |
|
GCOVR code coverage report https://1202.json.prtest2.cppalliance.org/gcovr/index.html Build time: 2026-09-30 18:17:56 UTC |
|
|
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.

Repro:
parse("0e400")with default options returns a double that is NaN, andserializeof that value emitsnull, so the number changes JSON type on a round trip.0e309,-0e400,0.0e400and0E+400behave the same. The same literals give0and-0undernumber_precision::precise, and1e400gives infinity as intended.Cause:
dec_to_floatscales the mantissa withx * pow10(e), andpow10returns infinity for any exponent above 308. With a zero mantissa that product is0 * inf, which is NaN.Fix: return the already signed zero before the scaling when the mantissa is zero, so
-0e400gives-0.0like the precise path. The two addedgrind_doublecases fail on develop (13 assertions across the split points) and pass with the change.