Skip to content

Conversation

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Nov 23, 2025

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

@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 Nov 23, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 23, 2025

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

@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 23, 2025
@juntyr
Copy link
Contributor

juntyr commented Nov 23, 2025

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
Member

Amanieu commented Nov 25, 2025

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.

@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 26, 2025
@RalfJung RalfJung changed the title float::clamp: make current treatment of signed zeros explicit float::clamp: make treatment of signed zeros unspecified Nov 26, 2025
@RalfJung
Copy link
Member Author

@Amanieu something like this?

@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 26, 2025
@rust-log-analyzer

This comment has been minimized.

@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 27, 2025
@Amanieu
Copy link
Member

Amanieu commented Nov 27, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 27, 2025

📌 Commit 69d3218 has been approved by Amanieu

It is now in the queue for this repository.

@bors bors 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
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
Member Author

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:main Nov 27, 2025
11 checks passed
@rustbot rustbot 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
Member

the8472 commented Nov 27, 2025

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

@RalfJung
Copy link
Member Author

RalfJung commented Nov 27, 2025 via email

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

Amanieu commented Nov 27, 2025

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
Member Author

Ah, thanks for clarifying. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant 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