lagoon: fix %mod jet to C-fmod truncation + NaN on divide-by-zero#55
Merged
Conversation
Both vendored jet variants (lagoon/vere standard + lagoon/vere64 64-bit) had the %mod ray-op and mod-scalar jets rounding the quotient to nearest (IEEE remainder) and returning the dividend on a zero divisor, diverging from the Hoon +mod (C fmod: truncate toward zero; NaN on /0 or a non-finite operand). Truncate the quotient with softfloat_round_minMag and return the width's qNaN on a non-finite quotient, in both u3qi_la_mod_i754 and u3qi_la_mods_i754, all four widths. Mirrors Vere PR #1022, verified on the live ~tex ship (5 mod 3 -> 2.0; 5 mod 0 -> NaN; f32 and f64). 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.
The vendored
%modjets diverged from the Hoon+mod(fixed Hoon-side in #52 /sigilante/fix-i754-mod): they rounded the quotient to nearest (IEEE remainder) and returned the dividend on a zero divisor, where+moddoes Cfmod— truncate the quotient toward zero, and return NaN on a zero divisor or non-finite operand.This fixes both vendored jet variants:
lagoon/vere/noun/jets/i/lagoon.c(standard;maroon/...symlinks here)lagoon/vere64/noun/jets/lagoon.c(64-bit)In both
u3qi_la_mod_i754(ray-mod) andu3qi_la_mods_i754(mod-scalar), all four widths (f16/f32/f64/f128):softfloat_round_minMaginstead of the active mode.Purely SoftFloat-level (
f*_to_i64's mode is an explicit arg), so the stateless SoftBLAS interface is untouched.Verification
The 64-bit variant of this fix is Vere PR urbit/vere#1022, verified on a live ship (
~tex):5 mod 3(f64)2.0-1.05 mod 0(f64)NaN5.05 mod 32.05 mod 0NaN5.05 mod 3(f32)2.0-1.0🤖 Generated with Claude Code