Skip to content

/lib/fixed: round out scalar API (abs, comparisons, mod, constructors)#43

Merged
sigilante merged 1 commit into
mainfrom
sigilante/fixed-phase-a
Jun 1, 2026
Merged

/lib/fixed: round out scalar API (abs, comparisons, mod, constructors)#43
sigilante merged 1 commit into
mainfrom
sigilante/fixed-phase-a

Conversation

@sigilante
Copy link
Copy Markdown
Collaborator

Phase A of the fixed-point buildout — completes the /lib/fixed scalar API
so it's usable beyond raw hex and ready for Lagoon %fixp integration (Phase B,
to follow).

All new arms delegate to the width-keyed +twid door of /lib/twoc already
used 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 equal
    precision, returning loobeans. equ is bit equality (two's-complement has
    no negative zero).
  • 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.

Note

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 (same
/lib/twoc-face shadowing family that bit the earlier rebuild).

Tests

/tests/lib/fixed grows from 7 to 12 arms (abs, mod incl. negative,
comparisons, from-s, rs round-trip). All pass on ~hex. Expected values are
hand-derived and consistent with the existing fractions/spfpm oracle;
extending tools/fixed_check.py to the new ops is a cheap optional follow-up.

🤖 Generated with Claude Code

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>
@sigilante sigilante merged commit 1d379b0 into main Jun 1, 2026
@sigilante sigilante deleted the sigilante/fixed-phase-a branch June 1, 2026 20:28
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