Skip to content

float::clamp: make treatment of signed zeros unspecified - #149238

Merged
bors merged 1 commit into
rust-lang:mainfrom
RalfJung:clamp-signed-zeros
Nov 27, 2025
Merged

float::clamp: make treatment of signed zeros unspecified#149238
bors merged 1 commit into
rust-lang:mainfrom
RalfJung:clamp-signed-zeros

Conversation

@RalfJung

@RalfJungRalfJung commented Nov 23, 2025

Copy link
Copy Markdown
Member

Fixes#83984 by explicitly documenting that we do not specify the treatment of signed zeros in clamp. @rust-lang/libs-api Is this what you'd like to see?

Cc @tgross35@thomcc

@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? @scottmcm

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

@RalfJungRalfJung added the I-libs-api-nominated [DEPRECATED; DO NOT USE] label Nov 23, 2025
@juntyr

Copy link
Copy Markdown
Contributor

I have the unfortunate pleasure of working on a project where the sign of 0.0 matters. Adding documentation for what Rust guarantees is a very positive step. For functions where the sign is ignored, it would be good to also point to alternative functions where -0.0 < +0.0, if they exist, or mention that the functionality can be implemented in some way

@Amanieu

Copy link
Copy Markdown
Member

I don't think we should guarantee that these compare equal since that would rule out the ability to use the much more efficient min and max operations (usually a single CPU instruction). I would use the same wording as f32::{min,max} that says that when +0.0 are -0.0 compared, either may be returned non-deterministically.

@AmanieuAmanieu removed the I-libs-api-nominated [DEPRECATED; DO NOT USE] label Nov 26, 2025
@RalfJungRalfJung changed the title float::clamp: make current treatment of signed zeros explicitfloat::clamp: make treatment of signed zeros unspecifiedNov 26, 2025
@RalfJung

Copy link
Copy Markdown
MemberAuthor

@Amanieu something like this?

@RalfJungRalfJung added the I-libs-api-nominated [DEPRECATED; DO NOT USE] label Nov 26, 2025
@rust-log-analyzer

This comment has been minimized.

@AmanieuAmanieu removed the I-libs-api-nominated [DEPRECATED; DO NOT USE] label Nov 27, 2025
@Amanieu

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Nov 27, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 69d3218 has been approved by Amanieu

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 27, 2025
@ZalatharZalathar mentioned this pull request Nov 27, 2025
bors added a commit that referenced this pull request Nov 27, 2025
Rollup of 8 pull requests
Successful merges:
- #149238 (float::clamp: make treatment of signed zeros unspecified)
- #149270 (implement `Iterator::{exactly_one, collect_array}`)
- #149295 (Suggest _bytes versions of endian-converting methods)
- #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
@RalfJung

Copy link
Copy Markdown
MemberAuthor

Doesn't this require some sort of team decision, since it fixes a previously undescribed part of the API for clamp?

@bors
bors merged commit 13c2640 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 #149238 - RalfJung:clamp-signed-zeros, r=Amanieu
float::clamp: make treatment of signed zeros unspecified
Fixes#83984 by explicitly documenting that we do not specify the treatment of signed zeros in `clamp`. `@rust-lang/libs-api` Is this what you'd like to see?
Cc `@tgross35` `@thomcc`
@the8472

Copy link
Copy Markdown
Member

Isn't non-deterministic return value pretty much a non-guarantee?

@RalfJung

RalfJung commented Nov 27, 2025 via email

Copy link
Copy Markdown
MemberAuthor

@RalfJung
RalfJung deleted the clamp-signed-zeros branch November 27, 2025 14:09
@Amanieu

Copy link
Copy Markdown
Member

FWIW this was actually discussed in the libs-api meeting this week and it was a team decision to make this change to the docs.

@RalfJung

Copy link
Copy Markdown
MemberAuthor

Ah, thanks for clarifying. :)

github-actionsBot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Dec 1, 2025
Rollup of 8 pull requests
Successful merges:
- rust-lang/rust#149238 (float::clamp: make treatment of signed zeros unspecified)
- rust-lang/rust#149270 (implement `Iterator::{exactly_one, collect_array}`)
- rust-lang/rust#149295 (Suggest _bytes versions of endian-converting methods)
- rust-lang/rust#149332 (fix rustdoc search says “Consider searching for "null" instead.” rust-lang/rust#149324)
- rust-lang/rust#149349 (Fix typo in comment.)
- rust-lang/rust#149353 (Tidying up UI tests [3/N])
- rust-lang/rust#149355 (Document that `build.description` affects symbol mangling and crate IDs)
- rust-lang/rust#149360 (Enable CI download for windows-gnullvm)
r? `@ghost`
`@rustbot` modify labels: rollup
github-actionsBot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jan 20, 2026
…nieu
float::clamp: make treatment of signed zeros unspecified
Fixesrust-lang#83984 by explicitly documenting that we do not specify the treatment of signed zeros in `clamp`. `@rust-lang/libs-api` Is this what you'd like to see?
Cc `@tgross35` `@thomcc`
github-actionsBot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jan 20, 2026
Rollup of 8 pull requests
Successful merges:
- rust-lang#149238 (float::clamp: make treatment of signed zeros unspecified)
- rust-lang#149270 (implement `Iterator::{exactly_one, collect_array}`)
- rust-lang#149295 (Suggest _bytes versions of endian-converting methods)
- rust-lang#149332 (fix rustdoc search says “Consider searching for "null" instead.” rust-lang#149324)
- rust-lang#149349 (Fix typo in comment.)
- rust-lang#149353 (Tidying up UI tests [3/N])
- rust-lang#149355 (Document that `build.description` affects symbol mangling and crate IDs)
- rust-lang#149360 (Enable CI download for windows-gnullvm)
r? `@ghost`
`@rustbot` modify labels: rollup
ghaaj pushed a commit to ghaaj/polygrammar that referenced this pull request Aug 7, 2026
Rollup of 8 pull requests
Successful merges:
- rust-lang/rust#149238 (float::clamp: make treatment of signed zeros unspecified)
- rust-lang/rust#149270 (implement `Iterator::{exactly_one, collect_array}`)
- rust-lang/rust#149295 (Suggest _bytes versions of endian-converting methods)
- rust-lang/rust#149332 (fix rustdoc search says “Consider searching for "null" instead.” rust-lang/rust#149324)
- rust-lang/rust#149349 (Fix typo in comment.)
- rust-lang/rust#149353 (Tidying up UI tests [3/N])
- rust-lang/rust#149355 (Document that `build.description` affects symbol mangling and crate IDs)
- rust-lang/rust#149360 (Enable CI download for windows-gnullvm)
r? `@ghost`
`@rustbot` modify labels: rollup
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 17, 2026
Rollup of 8 pull requests
Successful merges:
- rust-lang/rust#149238 (float::clamp: make treatment of signed zeros unspecified)
- rust-lang/rust#149270 (implement `Iterator::{exactly_one, collect_array}`)
- rust-lang/rust#149295 (Suggest _bytes versions of endian-converting methods)
- rust-lang/rust#149332 (fix rustdoc search says “Consider searching for "null" instead.” rust-lang/rust#149324)
- rust-lang/rust#149349 (Fix typo in comment.)
- rust-lang/rust#149353 (Tidying up UI tests [3/N])
- rust-lang/rust#149355 (Document that `build.description` affects symbol mangling and crate IDs)
- rust-lang/rust#149360 (Enable CI download for windows-gnullvm)
r? `@ghost`
`@rustbot` modify labels: rollup
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.

Float min/max/clamp follow IEEE754-2008 (and not IEEE754-2019) WRT negative zeros

8 participants

@RalfJung@rustbot@juntyr@Amanieu@rust-log-analyzer@bors@the8472@scottmcm