Skip to content

f*::NAN: guarantee that this is a quiet NaN #139483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2025
Merged

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Apr 7, 2025

I think we should guarantee that this is a quiet NaN. This then implies that programs not using f*::from_bits (or unsafe type conversions) are guaranteed to only work with quiet NaNs. It would be awkward if people start to write 0.0 / 0.0 instead of using the constant just because they want to get a guaranteed-quiet NaN.

This is a @rust-lang/libs-api change. The definition of this constant currently is 0.0 / 0.0, which is already guaranteed to be a quiet NaN. So all this does is forward that guarantee to our users.

@rustbot
Copy link
Collaborator

rustbot commented Apr 7, 2025

r? @thomcc

rustbot has assigned @thomcc.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 7, 2025
@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Apr 7, 2025
@m-ou-se m-ou-se added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. labels Apr 7, 2025
@m-ou-se
Copy link
Member

m-ou-se commented Apr 7, 2025

@rfcbot merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 7, 2025

Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 7, 2025

The Miri subtree was changed

cc @rust-lang/miri

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Apr 7, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 7, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@bstrie
Copy link
Contributor

bstrie commented Apr 10, 2025

Is it worth considering the alternative of making no guarantees about f*::NAN, and instead providing f*::QUIET_NAN and f*::SIGNALING_NAN?

@RalfJung
Copy link
Member Author

RalfJung commented Apr 10, 2025

I think adding a SIGNALING_NAN might be worth considering, but I'd say NAN is the better name for QUIET_NAN since it's what you should use most of the time. Signaling NaNs show non-portable behavior much more quickly than quiet NaNs.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Apr 17, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Apr 17, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@tgross35
Copy link
Contributor

r? tgross35
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 17, 2025

📌 Commit 0da46d1 has been approved by tgross35

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 17, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#139351 (Autodiff batching2)
 - rust-lang#139483 (f*::NAN: guarantee that this is a quiet NaN)
 - rust-lang#139498 (Ignore zero-sized types in wasm future-compat warning)
 - rust-lang#139967 (Introduce and use specialized `//@ ignore-auxiliary` for test support files instead of using `//@ ignore-test`)
 - rust-lang#139969 (update libc)
 - rust-lang#139971 (Make C string merging test work on MIPS)
 - rust-lang#139974 (Change `InterpCx::instantiate*` function visibility to pub)
 - rust-lang#139977 (Fix drop handling in `hint::select_unpredictable`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b6e48d3 into rust-lang:master Apr 18, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 18, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2025
Rollup merge of rust-lang#139483 - RalfJung:nan, r=tgross35

f*::NAN: guarantee that this is a quiet NaN

I think we should guarantee that this is a quiet NaN. This then implies that programs not using `f*::from_bits` (or unsafe type conversions) are guaranteed to only work with quiet NaNs. It would be awkward if people start to write `0.0 / 0.0` instead of using the constant just because they want to get a guaranteed-quiet NaN.

This is a `@rust-lang/libs-api` change. The definition of this constant currently is `0.0 / 0.0`, which is already guaranteed to be a quiet NaN. So all this does is forward that guarantee to our users.
@tgross35
Copy link
Contributor

I didn't think of this until just now but we should add a test ensuring the top mantissa bit is set

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 19, 2025
f*::NAN: guarantee that this is a quiet NaN

I think we should guarantee that this is a quiet NaN. This then implies that programs not using `f*::from_bits` (or unsafe type conversions) are guaranteed to only work with quiet NaNs. It would be awkward if people start to write `0.0 / 0.0` instead of using the constant just because they want to get a guaranteed-quiet NaN.

This is a `@rust-lang/libs-api` change. The definition of this constant currently is `0.0 / 0.0`, which is already guaranteed to be a quiet NaN. So all this does is forward that guarantee to our users.
@RalfJung RalfJung deleted the nan branch April 20, 2025 09:12
@RalfJung
Copy link
Member Author

@tgross35 what's the best way to get the top mantissa bit for our various float types?

@tgross35
Copy link
Contributor

I think x.to_bits() & (1 << (F::MANTISSA_DIGITS - 2)) != 0 should work

ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 22, 2025
test_nan: ensure the NAN contant is quiet

Follow-up to rust-lang#139483

r? `@tgross35`
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 22, 2025
test_nan: ensure the NAN contant is quiet

Follow-up to rust-lang#139483

r? ``@tgross35``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2025
Rollup merge of rust-lang#140149 - RalfJung:test_nan, r=tgross35

test_nan: ensure the NAN contant is quiet

Follow-up to rust-lang#139483

r? ``@tgross35``
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Apr 23, 2025
test_nan: ensure the NAN contant is quiet

Follow-up to rust-lang/rust#139483

r? ``@tgross35``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants