Skip to content

Fix quad mod-scalar reciprocal constant (0.0 -> 1.0)#25

Merged
sigilante merged 1 commit into
mainfrom
sigilante/quad-mods-reciprocal-fix
May 30, 2026
Merged

Fix quad mod-scalar reciprocal constant (0.0 -> 1.0)#25
sigilante merged 1 commit into
mainfrom
sigilante/quad-mods-reciprocal-fix

Conversation

@sigilante
Copy link
Copy Markdown
Collaborator

Summary

u3qi_la_mods_i754 case 7 (quad precision) computes the reciprocal 1/n and then multiplies through the array. The 128-bit numerator was written as {SB_REAL128L_ONE, SB_REAL128U_ZERO} — which is 0.0, not 1.0 (SB_REAL128U_* is the upper/exponent word: SB_REAL128U_ONE = 0x3fff000000000000, SB_REAL128U_ZERO = 0x0).

So the reciprocal evaluated to 0, and quad mod-scalar multiplied every element by zero and returned x unchanged.

  • Other precisions (%4/%5/%6) were unaffected.
  • The sibling divs reciprocal (~line 1564) already used the correct {..._ONE, ..._ONE} = 1.0.

Fix

Changed SB_REAL128U_ZEROSB_REAL128U_ONE at the reciprocal site in all three jet files:

  • lagoon/vere/noun/jets/i/lagoon.c
  • lagoon/vere64/noun/jets/lagoon.c
  • maroon/vere/noun/jets/i/lagoon.c

Test

Added a quad mod-scalar regression 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 in mod.)

🤖 Generated with Claude Code

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>
@sigilante sigilante merged commit 198393e into main May 30, 2026
@sigilante sigilante deleted the sigilante/quad-mods-reciprocal-fix branch May 30, 2026 14:37
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