fix: keep the sign of negative JSON floats with a zero integer part - #416
Open
edubraqd wants to merge 1 commit into
Open
fix: keep the sign of negative JSON floats with a zero integer part#416edubraqd wants to merge 1 commit into
edubraqd wants to merge 1 commit into
Conversation
JsonParse-Float took the fractional multiplier's sign from the parsed integer part. For a value such as "-0.5" the integer part is 0, so the sign was dropped and the result came back positive (+0.5). This affected every value in the open interval (-1, 0), including exponent forms like "-0.5e1". Detect the "-" sign directly from the input before parsing and use it to drive the fractional multiplier. Adds regression tests for small and exponent-bearing negative fractions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
JsonParse-Floatloses the sign of any JSON number in the open interval(-1, 0). The result comes back positive:-0.5+0.5-0.5-0.0009+0.0009-0.0009-0.5e1+5.0-5.0-1.5-1.5-1.5(unaffected)Root cause
The fractional multiplier's sign was taken from the parsed integer part:
For
-0.5the integer part is0, andJsonParse-Integerreturns0(it captures the-sign but multiplies it by a zero magnitude). SoLK-VALUE < 0is false, the multiplier stays positive, and the sign is dropped. Values like-1.5work only because their integer magnitude is non-zero.Fix
Detect the
-sign directly from the input before parsing, and use that flag to drive the fractional multiplier. The peek uses a separate offset and the same whitespace-skipping the integer parser already does, so it does not consume input or change the parse position.Tests
Added three regression cases to
Test-JsonParse-Float:-0.5,-0.0009, and-0.5e1. Full suite: 315 run, 0 failed.🤖 Generated with Claude Code