Skip to content

arvo: posit number library (lib/unum) - #7374

Open
sigilante wants to merge 3 commits into
sigilante/twocfrom
sigilante/unum
Open

sigilante wants to merge 3 commits into
sigilante/twocfrom
sigilante/unum

Conversation

@sigilante

@sigilante sigilante commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Adds lib/unum.hoon — Standard-2022 posit arithmetic (es=2 uniform across
widths): encode/decode, elementary ops, transcendentals, and quire support.
Pure Hoon.

Stacked on #7373 (lib/twoc) — unum uses /+ twoc for two's-complement
helpers. Retarget to develop once #7373 merges.

tests/lib/unum-{core,fns,edge}.hoon included. Verified: arvo compiles and all
three suites are green on a fresh %zuse-408 ship.

Second of the numerics-library series (twoc → unum → fixed → complex).

🤖 Generated with Claude Code


Refreshed to numerics main (2026-09-21)

This PR was cut before two numerics changes landed. Commit 557459ee18 mirrors numerics main's lib/unum.hoon and its tests byte-for-byte:

Nothing from the earlier commits is lost — every line of the audit-fix commit is present in numerics main. unum uses only twoc door arms that #7373 defines.

Re-verified on a fresh fakezod (hoon-135/zuse-408) against #7373's lib/twoc: unum-core 12, unum-edge 28, unum-fns 15 — all 55 green.

Add lib/unum.hoon (numerics /lib/unum): Standard-2022 posit arithmetic
(es=2 uniform across widths) -- encode/decode, the elementary ops and
transcendentals, and quire support. Pure Hoon; depends on /+ twoc for
two's-complement helpers.

Add tests/lib/unum-core, unum-fns, unum-edge. Verified: arvo compiles and
all three suites are green on a fresh %zuse-408 ship.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- H12: document ++fdp silent truncation behavior
- M24-M25: doccord correctness fixes
- L15: add per-arm doccords to seven quire op arms

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t hints)

This PR was cut from urbit/numerics before two changes landed there; this
commit mirrors numerics main's lib/unum.hoon and its tests byte-for-byte, per
numerics' merge guide (numerics Hoon is ground truth, mirrored to
pkg/arvo/lib/).

1. Correctly rounded transcendentals (urbit/numerics#71).  The series
   expansions this PR carried were one ulp off for several posit32 results.
   Measured on a ship, the previous head of this branch returned the left-hand
   column; numerics' exact-rational posit encoder (80-digit mpmath) gives the
   right-hand one, which is what the refreshed library returns:

     op          before (series)   correctly rounded (now)
     exp(0.5)    0x4530.94c8       0x4530.94c7
     cos(0.5)    0x3e0a.9404       0x3e0a.9403
     tan(0.5)    0x38bd.a7ad       0x38bd.a7ae
     log(2)      0x3b17.2180       0x3b17.217f

   #71 replaced them with range-reduced Chebyshev approximations and refreshed
   tests/lib/unum-edge and unum-fns to match; both come across here too
   (unum-core is unchanged).

2. Jet hints (urbit/numerics#65, #79).  The library now carries its ~%/~/
   hints, matching the registration in urbit/vere#1046, whose SoftUnum jets are
   already on the same Chebyshev basis -- so the Hoon and the jets agree
   bit-for-bit.  Without #1046 the hints are inert.  lib/math in #7372 ships
   its hints the same way.

Nothing from this PR's previous commits is lost: every line of the audit-fix
commit (d22c333) is present in numerics main.  unum calls only the twoc
door arms gth/lth/gte/lte/msb, all defined in #7373's lib/twoc, and nothing
else in the tree references lib/unum.

Verified on a fresh fakezod (hoon-135/zuse-408) with #7373's lib/twoc and this
tree's lib/test: tests/lib/unum-core 12, unum-edge 28, unum-fns 15 -- all 55
green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TgBnKsUPYzkoPZonjePnaq
sigilante added a commit that referenced this pull request Sep 22, 2026
Mirrors urbit/numerics main's lib/twoc.hoon byte-for-byte, per numerics' merge
guide (numerics Hoon is ground truth, mirrored to pkg/arvo/lib/).  This PR was
cut before urbit/numerics 0955657 added the library's jet hints.

The change is hints only -- no arm's behavior changes:

  ~%  %non  ..part  ~       jet registration, nested in %non like /lib/unum
                            and /lib/math
  ~/  %twid                 on the door
  ~/  %add %neg %sub %mul %abs %div %rem %pow %gth %lth %lte %gte

Without registered jets the hints are inert.  lib/math in #7372 and lib/unum
in #7374 ship their hints the same way.  tests/lib/twoc.hoon is already
identical to numerics main, and every line of this PR's audit-fix commit
(a25539f) is present there.

Verified on a fresh fakezod (hoon-135/zuse-408) with the whole stack built on
this twoc: twoc 13, and the dependents unum (#7374, 55) and fixed (#7375, 13)
all green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TgBnKsUPYzkoPZonjePnaq
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