Skip to content

fix: keep the sign of negative JSON floats with a zero integer part - #416

Open
edubraqd wants to merge 1 commit into
meyfa:mainfrom
edubraqd:fix-jsonparse-float-negative-fraction
Open

fix: keep the sign of negative JSON floats with a zero integer part#416
edubraqd wants to merge 1 commit into
meyfa:mainfrom
edubraqd:fix-jsonparse-float-negative-fraction

Conversation

@edubraqd

@edubraqd edubraqd commented Sep 3, 2026

Copy link
Copy Markdown

Problem

JsonParse-Float loses the sign of any JSON number in the open interval (-1, 0). The result comes back positive:

input before after
-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:

IF LK-VALUE < 0
    MOVE -0.1 TO MULTIPLIER
ELSE
    MOVE 0.1 TO MULTIPLIER
END-IF

For -0.5 the integer part is 0, and JsonParse-Integer returns 0 (it captures the - sign but multiplies it by a zero magnitude). So LK-VALUE < 0 is false, the multiplier stays positive, and the sign is dropped. Values like -1.5 work 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.

make test
...
Tests run: 315
Tests failed: 0
Tests skipped: 6

🤖 Generated with Claude Code

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>
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.

1 participant