Skip to content

float: preserve NaN sign when propagating NaNs - #1239

Open
HuzaifaAbdulRehman wants to merge 1 commit into
rust-lang:mainfrom
HuzaifaAbdulRehman:fix-nan-sign-propagation
Open

float: preserve NaN sign when propagating NaNs#1239
HuzaifaAbdulRehman wants to merge 1 commit into
rust-lang:mainfrom
HuzaifaAbdulRehman:fix-nan-sign-propagation

Conversation

@HuzaifaAbdulRehman

@HuzaifaAbdulRehman HuzaifaAbdulRehman commented Jul 26, 2026

Copy link
Copy Markdown

Closes #1188.

Soft-float addition classified NaNs using sign-stripped representations and then reused those representations to construct the result. This discarded the sign bit when propagating an input NaN.

Use the original operand representation when setting the quiet bit, preserving the input sign and payload while quieting signaling NaNs. This also matches the corresponding compiler-rt behavior.

The regression tests check signaling and quiet NaNs in both operand positions for f16, f32, f64, and f128. They fail against main with sign-stripped results and pass with this change.

Validation:

  • cargo +nightly test -p builtins-test --test addsub --no-default-features -j 1
  • cargo +nightly test --workspace --no-default-features --exclude musl-math-sys -j 1
  • cargo +nightly fmt --all -- --check
  • git diff --check

The unexcluded workspace command requires the musl source fixture, which is not present in this shallow checkout.

AI assistance: I used OpenAI Codex to assist with investigation, implementation, and validation. I reviewed the changes and test results.

@HuzaifaAbdulRehman

Copy link
Copy Markdown
Author

Hi @tgross35, this has been open for a couple weeks with all 44 checks passing and no conflicts with main. Happy to make any changes if you'd like a different approach, just let me know. Thanks for taking a look when you get a chance.

@tgross35

Copy link
Copy Markdown
Contributor

Yeah sorry, I have seen this but have been a bit backed up for reviews, it may be another week or two since we've come across some higher priority things.

As a quick note, it looks like your PR description may be machine-generated; please rewrite it, all communication with humans needs to be handwritten. Also the title should be more specific, this is only touches addition (similarly, it shouldn't close the linked issue).

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.

Soft float arithmetic should propagate NaN sign

2 participants