Skip to content

return zero from dec_to_float when the mantissa is zero - #1202

Open
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:parser-zero-mantissa-nan
Open

Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:parser-zero-mantissa-nan

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: parse("0e400") with default options returns a double that is NaN, and serialize of that value emits null, so the number changes JSON type on a round trip. 0e309, -0e400, 0.0e400 and 0E+400 behave the same. The same literals give 0 and -0 under number_precision::precise, and 1e400 gives infinity as intended.
Cause: dec_to_float scales the mantissa with x * pow10(e), and pow10 returns infinity for any exponent above 308. With a zero mantissa that product is 0 * inf, which is NaN.
Fix: return the already signed zero before the scaling when the mantissa is zero, so -0e400 gives -0.0 like the precise path. The two added grind_double cases fail on develop (13 assertions across the split points) and pass with the change.

@cppalliance-bot

Copy link
Copy Markdown

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

@cppalliance-bot

Copy link
Copy Markdown

GCOVR code coverage report https://1202.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1202.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1202.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-09-30 18:17:56 UTC

@cppalliance-bot

Copy link
Copy Markdown

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.

2 participants