Skip to content

Make mod jet round the quotient with the active rounding mode#27

Merged
sigilante merged 1 commit into
mainfrom
sigilante/mod-dynamic-rounding
May 30, 2026
Merged

Make mod jet round the quotient with the active rounding mode#27
sigilante merged 1 commit into
mainfrom
sigilante/mod-dynamic-rounding

Conversation

@sigilante
Copy link
Copy Markdown
Collaborator

Summary

The mod/mods jets reduced x/n to an integer with a hardcoded softfloat_round_minMag (truncation toward zero), but the Hoon reference rounds that quotient with toi under the active rounding mode (fun-scalar %mod, e.g. lagoon.hoon:1061). The two disagree for any mode other than %z, and even under the default %n for negative quotients — e.g. 5 mod 3 = 5 - 3·round(5/3) = -1 under round-nearest, vs 2 under truncation.

Per maintainer direction the jet should match Hoon (SoftBLAS is being aligned upstream similarly).

Fix

Use softfloat_roundingMode — already established by _set_rounding(rnd) in both the u3wi_la_mod and u3wi_la_mods wrappers — for the quotient round in u3qi_la_mod_i754 and u3qi_la_mods_i754 (all four precisions), across all three jet files. The 8 mod/mods sites per file are changed; the range/linspace ceil-count sites stay on minMag (unrelated). The now-misnamed floor_result/floor_float locals are renamed to quot_round/quot_round_f, and the "floor" comments corrected.

Test

Added a mod regression test: 5 mod 3 = -1 under the default %n mode (the old truncating jet returned 2).

Note

This is a behavioral change to mod for non-%z modes and negatives. It aligns the jet with the Hoon reference; reviewers fixing SoftBLAS upstream should confirm the upstream mod matches.

🤖 Generated with Claude Code

The mod/mods jets hardcoded softfloat_round_minMag (truncation toward
zero) when reducing x/n to an integer, while the Hoon reference rounds
that quotient with `toi` under the active rounding mode. The two
disagreed for any mode other than %z, and for negatives even under the
default %n (e.g. 5 mod 3 = -1 under round-nearest, not 2).

Use softfloat_roundingMode (already set by _set_rounding(rnd) in both
the mod and mods wrappers) for the quotient round in u3qi_la_mod_i754
and u3qi_la_mods_i754, all four precisions, in all three jet files. The
range/linspace ceil-count sites are left on minMag. Rename the now-
misnamed floor_result/floor_float locals to quot_round/quot_round_f and
correct the comments. Add a mod regression test (5 mod 3 = -1 under %n).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sigilante sigilante force-pushed the sigilante/mod-dynamic-rounding branch from 272dd8e to d96c5cf Compare May 30, 2026 14:47
@sigilante sigilante merged commit 31b5302 into main May 30, 2026
@sigilante sigilante deleted the sigilante/mod-dynamic-rounding branch May 30, 2026 14:47
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