/lib/fixed: round out scalar API (abs, comparisons, mod, constructors)#43
Merged
Conversation
Phase A of the fixed-point buildout. All new arms delegate to the same width-keyed +twid door of /lib/twoc already used by add/sub/mul/div, so sign handling stays shared and single-sourced. - abs, mod (signed remainder, sign of dividend, via twid +rem). - gth/gte/lth/lte/equ/neq: signed comparisons at equal precision, returning loobeans (equ is bit equality; two's-complement has no -0). - from-s: encode a whole signed integer (n * 2^b). - from-rs / to-rs: single-precision IEEE float bridge (round to nearest), the first way to construct/read fractional values without raw hex. Escaped the internal gth/lte uses in scale/hi/lo to ^gth/^lte so the new same-named arms don't shadow the standard ones (the /lib/twoc-face shadowing family). Tests: /tests/lib/fixed grows to 12 arms (abs, mod incl. negative, comparisons, from-s, rs round-trip); all pass on ~hex. 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.
Phase A of the fixed-point buildout — completes the
/lib/fixedscalar APIso it's usable beyond raw hex and ready for Lagoon
%fixpintegration (Phase B,to follow).
All new arms delegate to the width-keyed
+twiddoor of/lib/twocalreadyused by
add/sub/mul/div, keeping sign handling single-sourced.New arms
abs,mod(signed remainder, sign of dividend, via twid+rem).gth/gte/lth/lte/equ/neq— signed comparisons at equalprecision, returning loobeans.
equis bit equality (two's-complement hasno negative zero).
from-s— encode a whole signed integer (n * 2^b).from-rs/to-rs— single-precision IEEE float bridge (round tonearest), the first way to construct/read fractional values without raw hex.
Note
Escaped the internal
gth/lteuses inscale/hi/loto^gth/^lteso the new same-named arms don't shadow the standard ones (same
/lib/twoc-face shadowing family that bit the earlier rebuild).Tests
/tests/lib/fixedgrows from 7 to 12 arms (abs, mod incl. negative,comparisons, from-s, rs round-trip). All pass on
~hex. Expected values arehand-derived and consistent with the existing
fractions/spfpmoracle;extending
tools/fixed_check.pyto the new ops is a cheap optional follow-up.🤖 Generated with Claude Code