Fix value-kind mismatch in ffc_negative_digit_comp (float slow path)#4
Open
fcostaoliveira wants to merge 1 commit into
Open
Fix value-kind mismatch in ffc_negative_digit_comp (float slow path)#4fcostaoliveira wants to merge 1 commit into
fcostaoliveira wants to merge 1 commit into
Conversation
ffc_negative_digit_comp built the rounded-down reference value `b` with a hardcoded FFC_VALUE_KIND_DOUBLE, then read it back via ffc_to_extended_halfway(b, vk). For vk == FFC_VALUE_KIND_FLOAT this writes the 8-byte double member of the ffc_value union and reads back the 4-byte float member, so `theor` is computed from garbage and the big-integer tie-break can round the wrong way. Pass the caller's vk consistently. Latent for normal inputs (the shortest-form exhaustive sweep never reaches this path), but real for over-precise hard-to-round float inputs with a negative exponent: ~1.07e9 binary32 midpoints round to the wrong neighbor under the bug, e.g. "1.1755301539980510070448986385130987351758e-38" -> 0x00800100 instead of the correct 0x008000ff (per strtof). Adds four such midpoint cases to float_cases.csv (fail before, pass after); the full float exhaustive suite is "all ok" with the fix. 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.
Summary
ffc_negative_digit_comp(the negative-exponent big-integer slow path) built its rounded-down reference valuebwith a hardcodedFFC_VALUE_KIND_DOUBLE, then read it back with the caller's kind:For
vk == FFC_VALUE_KIND_FLOATthis writes the 8-bytedoublemember of theffc_valueunion and reads back the 4-bytefloatmember, sotheoris garbage and the big-integer tie-break can round the wrong way. The fix is one token: pass the caller'svk.Impact
Latent for normal inputs (the shortest-form exhaustive sweep never reaches this path). But real for over-precise, hard-to-round
floatinputs with a negative exponent: a sweep of binary32 midpoints found ~1.07e9 inputs that round to the wrong neighbor under the bug, e.g.Tests
test_src/float_cases.csv(the harness comparesffc_from_chars<float>vsstrtofbit-for-bit). They fail before this change ("Test failures from csvs: 4"), pass after.test_exhaustive, all 2^32 values) is "all ok" with the fix; the strtof-parity midpoint sweep drops from ~1.07e9 mismatches to 0.make testpasses.