Skip to content

GPU: the rectangle fallback's f16 narrowing keeps NaN and rounds ties to even - #326

Open
RenzoWit35 wants to merge 1 commit into
fxceless:mainfrom
RenzoWit35:fix/245-rect-f16-nan-and-ties
Open

RenzoWit35 wants to merge 1 commit into
fxceless:mainfrom
RenzoWit35:fix/245-rect-f16-nan-and-ties

Conversation

@RenzoWit35

Copy link
Copy Markdown

Fixes #245.

f32_to_half in the CPU rectangle expansion sent NaN through the overflow branch (giving
infinity, 0x7c00) and rounded exact ties up (1 + 2^-11 gave 0x3c01). NaN now returns a quiet
NaN that keeps the sign (sign | 0x7e00), and normal values round ties to even like the
subnormal path already did. A rounding carry still moves into the exponent, and overflow still
gives infinity.

Tests: the issue's tie and NaN corners through expand_rects; NaN payloads, including one only
in the dropped bits; and a hand-written ties-to-even reference compared against every half
value, every halfway point and its neighbours, and a strided f32 sweep. All failed before.

Testing

On Windows 11, MSVC Rust 1.98.1, branch alone on top of main (2119b0e): cargo clippy --workspace --all-targets --locked -- -D warnings, the same with --all-features, and cargo test --workspace --locked all pass. The new regression test fails on main and passes here. All nine fix branches for #242-#250 also pass together when merged.

🤖 Generated with Claude Code

… to even (fxceless#245)

The CPU rectangle expansion narrows the generated fourth corner of an
R16_FLOAT element from f32. A NaN took the overflow path and became
infinity, and normal values exactly halfway between two halves always
rounded up (1 + 2^-11 gave 0x3c01, not 0x3c00). NaN now becomes a quiet
NaN with its sign, and normal values round ties to the even mantissa as
the subnormal path already did; overflow still gives infinity.

Tests: the tie and a quiet NaN corner through expand_rects, NaN payloads
only in dropped bits, and a check against a search-based ties-to-even
reference over every half, every halfway point and its neighbours, and a
sweep of f32 values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kaayzouee

Copy link
Copy Markdown

Duplicate of #315?

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.

GPU rectangle CPU fallback: FP16 conversion turns NaN into infinity and rounds ties up

2 participants