GPU: the rectangle fallback's f16 rounds to even and keeps NaN #396

Closed
JordanFableFur wants to merge 1 commit from upstream-pr/396 into main
JordanFableFur commented 2026-11-25 00:21:18 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-25T00:21:18Z.


What

The CPU rectangle fallback's f32-to-f16 conversion added 0x1000 to the mantissa unconditionally: an exact tie rounded up (1 + 2^-11 became 0x3c01 where round-to-nearest-even keeps 0x3c00; 2048 + 1 became 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_rects tests 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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594209043 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/396). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-25T00:21:18Z. --- ## What The CPU rectangle fallback's f32-to-f16 conversion added 0x1000 to the mantissa unconditionally: an exact tie rounded up (`1 + 2^-11` became 0x3c01 where round-to-nearest-even keeps 0x3c00; `2048 + 1` became 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_rects` tests 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.
chatgpt-codex-connector[bot commented 2026-11-25 01:11:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:21:29Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T00:23:01.820303Z 2a55fbf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7148424528 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/396#issuecomment-7148424528). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:21:29Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"2a55fbf85c0a8de0736ce7545c14e83ff7931a5e","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T00:23:01.820303Z">2026-11-25T00:23:01.820303Z</relative-time> | `2a55fbf` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
upstream-sync closed this pull request 2026-11-25 02:09:30 +00:00
kaayzouee commented 2026-11-25 02:10:09 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by kaayzouee on 2026-11-25T01:41:23Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149841334 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/396#issuecomment-7149841334). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T01:41:23Z. --- 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.
JordanFableFur commented 2026-11-25 02:10:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-25T01:46:09Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149934188 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/396#issuecomment-7149934188). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-25T01:46:09Z. --- 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.
JordanFableFur commented 2026-11-25 02:10:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-25T01:46:28Z.


Closing — as above, in favour of #315.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149940289 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/396#issuecomment-7149940289). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-25T01:46:28Z. --- Closing — as above, in favour of #315.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!396
No description provided.