Fix quad mod-scalar reciprocal constant (0.0 -> 1.0)#25
Merged
Conversation
u3qi_la_mods_i754 case 7 (quad) computes the reciprocal 1/n and then
multiplies, but the 128-bit numerator was written as
{SB_REAL128L_ONE, SB_REAL128U_ZERO} = 0.0 instead of
{SB_REAL128L_ONE, SB_REAL128U_ONE} = 1.0 (SB_REAL128U holds the
exponent word). The reciprocal evaluated to 0, so quad mod-scalar
multiplied by zero and returned x unchanged.
Other precisions were unaffected; the sibling divs reciprocal (line
~1564) already used the correct 1.0 constant. Fixed in all three jet
files and added a quad mod-scalar regression test (a=[7,5], n=3 -> [1,2];
the bug yields [7,5]).
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
u3qi_la_mods_i754case 7 (quad precision) computes the reciprocal1/nand then multiplies through the array. The 128-bit numerator was written as{SB_REAL128L_ONE, SB_REAL128U_ZERO}— which is0.0, not1.0(SB_REAL128U_*is the upper/exponent word:SB_REAL128U_ONE = 0x3fff000000000000,SB_REAL128U_ZERO = 0x0).So the reciprocal evaluated to
0, and quadmod-scalarmultiplied every element by zero and returnedxunchanged.%4/%5/%6) were unaffected.divsreciprocal (~line 1564) already used the correct{..._ONE, ..._ONE}=1.0.Fix
Changed
SB_REAL128U_ZERO→SB_REAL128U_ONEat the reciprocal site in all three jet files:lagoon/vere/noun/jets/i/lagoon.clagoon/vere64/noun/jets/lagoon.cmaroon/vere/noun/jets/i/lagoon.cTest
Added a quad
mod-scalarregression test:a=[7,5],n=3→[1,2]. The bug would return[7,5]. (Operands are positive, so it is independent of the separate truncation-vs-floor question inmod.)🤖 Generated with Claude Code