Skip to content

clarify float min/max behavios for NaNs and signed zeros - #149239

Merged
bors merged 2 commits into
rust-lang:mainfrom
RalfJung:float-intrinsics
Nov 27, 2025
Merged

clarify float min/max behavios for NaNs and signed zeros#149239
bors merged 2 commits into
rust-lang:mainfrom
RalfJung:float-intrinsics

Conversation

@RalfJung

@RalfJungRalfJung commented Nov 23, 2025

Copy link
Copy Markdown
Member

The first comment is internal, it only documents the intrinsics to more clearly say what they do.
This makes the currently implemented semantics more explicit, so one does not have to go look for the publicly exposed version of the operation to figure out what exactly should happen.

The second commit adds a NaN test to the doc comment for min/max, which matches what we already have for minimum/maximum.

@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbotrustbot 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 Nov 23, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

r? @tgross35

rustbot has assigned @tgross35.
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

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rust-log-analyzer

This comment has been minimized.

Comment threadlibrary/core/src/intrinsics/mod.rs Outdated
///
/// If one of the arguments is NaN, then the other argument is returned. If the inputs compare equal
/// (such as for the case of `+0.0` and `-0.0`), either input may be returned non-deterministically.
/// The last point makes this not quite the same as IEEE 754-2008 minNum.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think I misunderstood here -- looking at the 2008 version of the standard, it says

minNum(x, y) is the canonicalized number x if x < y, y if y < x, the canonicalized number if one
operand is a number and the other a quiet NaN. Otherwise it is either x or y, canonicalized (this
means results might differ among implementations). When either x or y is a signalingNaN, then the
result is according to 6.2.

So what we do actually does exactly match IEEE 754-2008 minNum, except for the usual differences in NaN treatment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was the difference between 2008 minNum and 2019 minimumNumber. I perpetually forget these details so wrote them down in a compiler-builtins issue that I refer to rust-lang/compiler-builtins#838.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, IEEE apparently has three versions of minimum/maximum now, if you also consider historic versions (that are still wide-spread). And their names are all super easy to mix up. What a mess. I am strongly inclined to come up with more distinct names for our intrinsics, but I'm not sure it's worth it given that everything around us would still use the confusing names...

@RalfJungRalfJung changed the title intrinsics: clarify float min/max behavios for NaNs and signed zerosclarify float min/max behavios for NaNs and signed zerosNov 24, 2025
@tgross35

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Nov 26, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 15290fa has been approved by tgross35

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
clarify float min/max behavios for NaNs and signed zeros
The first comment is internal, it only documents the intrinsics to more clearly say what they do.
This makes the currently implemented semantics more explicit, so one does not have to go look for the publicly exposed version of the operation to figure out what exactly should happen.
The second commit adds a NaN test to the doc comment for `min`/`max`, which matches what we already have for `minimum`/`maximum`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
clarify float min/max behavios for NaNs and signed zeros
The first comment is internal, it only documents the intrinsics to more clearly say what they do.
This makes the currently implemented semantics more explicit, so one does not have to go look for the publicly exposed version of the operation to figure out what exactly should happen.
The second commit adds a NaN test to the doc comment for `min`/`max`, which matches what we already have for `minimum`/`maximum`.
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
clarify float min/max behavios for NaNs and signed zeros
The first comment is internal, it only documents the intrinsics to more clearly say what they do.
This makes the currently implemented semantics more explicit, so one does not have to go look for the publicly exposed version of the operation to figure out what exactly should happen.
The second commit adds a NaN test to the doc comment for `min`/`max`, which matches what we already have for `minimum`/`maximum`.
@ZalatharZalathar mentioned this pull request Nov 26, 2025
bors added a commit that referenced this pull request Nov 26, 2025
Rollup of 19 pull requests
Successful merges:
- #148048 (Stabilize `maybe_uninit_write_slice`)
- #148641 (Add a diagnostic attribute for special casing const bound errors for non-const impls)
- #148765 (std: split up the `thread` module)
- #149074 (Add Command::get_env_clear)
- #149097 (num: Implement `uint_gather_scatter_bits` feature for unsigned integers)
- #149131 (optimize `slice::Iter::next_chunk`)
- #149190 (Forbid `CHECK: br` and `CHECK-NOT: br` in codegen tests (suggest `br {{.*}}` instead))
- #149239 (clarify float min/max behavios for NaNs and signed zeros)
- #149243 (Fix typo and clarify bootstrap change tracker entry)
- #149270 (implement `Iterator::{exactly_one, collect_array}`)
- #149295 (Suggest _bytes versions of endian-converting methods)
- #149301 (Motor OS: make decode_error_kind more comprehensive)
- #149306 (bootstrap: Miri now handles jemalloc like everything else)
- #149325 (rustdoc: add regression test for #140968)
- #149332 (fix rustdoc search says “Consider searching for "null" instead.” #149324)
- #149349 (Fix typo in comment.)
- #149353 (Tidying up UI tests [3/N])
- #149355 (Document that `build.description` affects symbol mangling and crate IDs)
- #149360 (Enable CI download for windows-gnullvm)
r? `@ghost`
`@rustbot` modify labels: rollup
@ZalatharZalathar mentioned this pull request Nov 27, 2025
bors added a commit that referenced this pull request Nov 27, 2025
Rollup of 12 pull requests
Successful merges:
- #147115 (More robust stack protector testing)
- #148048 (Stabilize `maybe_uninit_write_slice`)
- #148641 (Add a diagnostic attribute for special casing const bound errors for non-const impls)
- #149074 (Add Command::get_env_clear)
- #149097 (num: Implement `uint_gather_scatter_bits` feature for unsigned integers)
- #149131 (optimize `slice::Iter::next_chunk`)
- #149190 (Forbid `CHECK: br` and `CHECK-NOT: br` in codegen tests (suggest `br {{.*}}` instead))
- #149239 (clarify float min/max behavios for NaNs and signed zeros)
- #149243 (Fix typo and clarify bootstrap change tracker entry)
- #149301 (Motor OS: make decode_error_kind more comprehensive)
- #149306 (bootstrap: Miri now handles jemalloc like everything else)
- #149325 (rustdoc: add regression test for #140968)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit df6f24c into rust-lang:mainNov 27, 2025
11 checks passed
@rustbotrustbot added this to the 1.93.0 milestone Nov 27, 2025
rust-timer added a commit that referenced this pull request Nov 27, 2025
Rollup merge of #149239 - RalfJung:float-intrinsics, r=tgross35
clarify float min/max behavios for NaNs and signed zeros
The first comment is internal, it only documents the intrinsics to more clearly say what they do.
This makes the currently implemented semantics more explicit, so one does not have to go look for the publicly exposed version of the operation to figure out what exactly should happen.
The second commit adds a NaN test to the doc comment for `min`/`max`, which matches what we already have for `minimum`/`maximum`.
@RalfJung
RalfJung deleted the float-intrinsics branch November 27, 2025 14:09
github-actionsBot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jan 20, 2026
clarify float min/max behavios for NaNs and signed zeros
The first comment is internal, it only documents the intrinsics to more clearly say what they do.
This makes the currently implemented semantics more explicit, so one does not have to go look for the publicly exposed version of the operation to figure out what exactly should happen.
The second commit adds a NaN test to the doc comment for `min`/`max`, which matches what we already have for `minimum`/`maximum`.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@RalfJung@rustbot@rust-log-analyzer@tgross35@bors