-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
Feature gate: #![feature(clamp_min_max)]
This is a tracking issue for rust-lang/libs-team#665, which adds less confusable alternatives for x.min(y)
and x.max(y)
.
Public API
pub trait Ord: PartialOrd {
...
fn clamp_min(self, other: Self) -> Self { self.max(other) }
fn clamp_max(self, other: Self) -> Self { self.min(other) }
}
// and likewise in f16, f32, f64, and f128
Steps / History
(Remember to update the S-tracking-*
label when checking boxes.)
- ACP: ACP: Intuitive alternative for
.min()
and.max()
libs-team#665 - Implementation: Implement clamp_min and clamp_max #147786
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Is having these functions, where clamp_min == max, actually less confusing than the status quo?
- Should there be a lint that suggests replacing
x.max(y)
withx.clamp_min(y)
, andT::clamp_max(x, y)
withT::min(x, y)
? - What semantics should the float versions have regarding NaN?
NAN.max(0.0)
is 0, whileNAN.clamp(0.0, 0.0)
is NaN.
Footnotes
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.