Repository navigation
GPU: the rectangle fallback's f16 rounds to even and keeps NaN - #396
JordanFableFur wants to merge 1 commit into
Conversation
The CPU fallback's f32-to-f16 added 0x1000 unconditionally, so an exact tie went up (`1 + 2^-11` became 0x3c01, round-to-nearest-even keeps 0x3c00; `2048 + 1` became 0x6801, even keeps 0x6800), and any NaN became infinity. The conversion now decides by the dropped bits like the subnormal path (round up only past the halfway point, or on it when the kept mantissa is odd), carries a mantissa overflow into the exponent, and keeps a NaN: quiet, sign kept, payload where it fits. A regression covers the two ties, the NaN, the sign, and the two ways a finite value still reaches 0x7c00. AI use: written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Is this a duplicate of #315? Both fix round-to-nearest-even and NaN preservation in the CPU rectangle fallback. This is an automated message. If you believe it is incorrect, please reply with the relevant technical differences. |
|
Confirmed — #315 fixes the same issue and was opened first. One technical difference for whoever reviews: this PR keeps the NaN payload bits where they fit (the quiet bit set, payload shifted down) while #315 always returns the plain quiet NaN; both are valid round trips for the rectangle fallback, and #315's simpler form matches the issue's proposed fix. Closing in its favour. |
|
Closing — as above, in favour of #315. |
What
The CPU rectangle fallback's f32-to-f16 conversion added 0x1000 to the mantissa unconditionally: an exact tie rounded up (
1 + 2^-11became 0x3c01 where round-to-nearest-even keeps 0x3c00;2048 + 1became 0x6801 where even keeps 0x6800), and any NaN came back as infinity (0x7c00).The conversion now decides by the dropped bits, like the subnormal path already did (round up only past the halfway point, or on it when the kept mantissa is odd), carries a mantissa carry into the exponent, and keeps a NaN: quiet, sign kept, payload where it fits.
Fixes #245.
Testing
A regression covers the two ties from the issue, a NaN staying NaN with its sign, and the two ways a finite value still reaches 0x7c00 (past the largest half, and true infinity). The existing four
expand_rectstests are unchanged and pass.Validated on Windows CI (fork-run of the repository workflow): clippy both builds and the full test suite pass: https://github.com/JordanFableFur/victory-fork/actions/runs/45516463576
AI use: written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.