Make mod jet round the quotient with the active rounding mode#27
Merged
Conversation
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>
272dd8e to
d96c5cf
Compare
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
The
mod/modsjets reducedx/nto an integer with a hardcodedsoftfloat_round_minMag(truncation toward zero), but the Hoon reference rounds that quotient withtoiunder 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%nfor negative quotients — e.g.5 mod 3 = 5 - 3·round(5/3) = -1under round-nearest, vs2under 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 theu3wi_la_modandu3wi_la_modswrappers — for the quotient round inu3qi_la_mod_i754andu3qi_la_mods_i754(all four precisions), across all three jet files. The 8 mod/mods sites per file are changed; the range/linspaceceil-count sites stay onminMag(unrelated). The now-misnamedfloor_result/floor_floatlocals are renamed toquot_round/quot_round_f, and the "floor" comments corrected.Test
Added a
modregression test:5 mod 3 = -1under the default%nmode (the old truncating jet returned2).Note
This is a behavioral change to
modfor non-%zmodes and negatives. It aligns the jet with the Hoon reference; reviewers fixing SoftBLAS upstream should confirm the upstreammodmatches.🤖 Generated with Claude Code