Skip to content

Canonicalize NaN output in every value-producing routine (C1)#15

Merged
sigilante merged 1 commit into
masterfrom
fix/nan-canonicalization
May 30, 2026
Merged

Canonicalize NaN output in every value-producing routine (C1)#15
sigilante merged 1 commit into
masterfrom
fix/nan-canonicalization

Conversation

@sigilante
Copy link
Copy Markdown
Collaborator

SoftFloat is deterministic but propagates the (quieted) NaN payload — so a non-canonical NaN input produced a non-canonical NaN output, and only 5 of 40 routines (the asum family + qaxpy) canonicalized. Identical-magnitude results could be unequal nouns depending on the input NaN payload — which matters for Hoon equality. Per the decision to canonicalize everything:

  • Apply nan_unify_{h,s,d,q} to the output of every value-producing routine: dot, nrm2, scal, copy, swap, axpy, gemv (per written element / scalar result) and gemm (per written C element), all four precisions.
  • iamax excluded (returns an index). copy/swap canonicalize the NaNs they move.

test_nan.c feeds a non-canonical NaN (…0001) through each op and asserts the canonical pattern out — every op in single precision + d/h axpy spot-checks (q axpy already covered).

161/161 pass. Generalizes the qaxpy fix (B2/#12) to the whole library.

🤖 Generated with Claude Code

SoftFloat is deterministic but propagates a (quieted) NaN payload, so a
non-canonical NaN input produced a non-canonical NaN output -- and only 5
of 40 routines (the asum family + qaxpy) canonicalized. Identical-
magnitude results could therefore be unequal nouns depending on the input
NaN payload.

Apply nan_unify_{h,s,d,q} to the output of every value-producing routine:
dot, nrm2, scal, copy, swap, axpy, gemv (per written element / scalar
result) and gemm (per written C element), across all four precisions.
iamax is excluded (it returns an index, not a float). Copy and swap
canonicalize the NaNs they move, per the "all NaNs equal" contract.

New test_nan.c feeds a non-canonical NaN through each operation and
asserts the canonical pattern out (SINGNAN/DOUBNAN/HALFNAN), covering
every op in single precision plus d/h axpy spot-checks (q axpy already
covered by test_qaxpy_nan_unify).

161/161 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sigilante sigilante merged commit 92056ec into master May 30, 2026
1 check passed
@sigilante sigilante deleted the fix/nan-canonicalization branch May 30, 2026 16:53
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