Skip to content
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

Tracking issue for Ord::{min, max} #25663

Closed
kornelski opened this issue May 20, 2015 · 12 comments
Closed

Tracking issue for Ord::{min, max} #25663

kornelski opened this issue May 20, 2015 · 12 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@kornelski
Copy link
Contributor

It's seems inconsistent that floating-point types have a min method, but integer types don't.

And there's a standalone min() function that works with integer types, but it's not defined for floating-point types.

I don't have a strong preference for either style, but I'd prefer that at least one way of computing min/max was available for both floating point and integer types alike.

@Aatch Aatch added I-papercut T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 21, 2015
@Aatch
Copy link
Contributor

Aatch commented May 21, 2015

@aturon thoughts? Seems like adding an inherent method to integer types is the easiest way forward here.

Note that there are partial_min and partial_max functions for types that only implement PartialOrd.

@aturon
Copy link
Member

aturon commented May 21, 2015

+1 for an inherent method. I think this is just an oversight.

@alexcrichton
Copy link
Member

I believe @bluss commented to this effect already, but the idea here is that there is "one true min method" at cmp::min, but the floating point types use a slightly different algorithm (e.g. different guarantees about order and whatnot), hence they have their own methods.

I wouldn't be totally opposed to adding an inherent method, but we'd want to clearly document that it's just an alias to cmp::min

@nagisa
Copy link
Member

nagisa commented Jun 17, 2015

-1 for an inherent (or any other, really) method. Float’s min and max are just bindings to libm f{min.max}{f,}, while cmp::partial_{min,max} have their own, sane if you will, semantics. Adding inherent methods for integral types will make many-ways-to-do-the-same problem worse.

@frewsxcv
Copy link
Member

Ignoring the "many-ways-to-do-the-same problem" for a second, couldn't min and max just be generic 'provided methods' on the Ord trait?

@kornelski
Copy link
Contributor Author

For me this is a practical problem, because changing type needlessly changes syntax.

let a = 1.0;
let b = 2.0;
let c = a.max(b); // c = std::cmp::max(a,b)

I can't change a = 1; b = 2 without rewriting the third line.

I often write performance-sensitive graphics code, which I prototype on floats for ease of writing, and then where appropriate change to use integers for speed/memory efficiency. 90% of calculations just work, and max is one of the warts that doesn't.

@Mark-Simulacrum
Copy link
Member

@rust-lang/libs: Looks like this needs some thought; I've nominated. Possibly interesting for libz blitz discussion, too, since it relates to number types in wider library set; for example serde_json::Number doesn't implement min/max inherently, but should it?

I think that the things that have been brought up are:

@aturon
Copy link
Member

aturon commented May 23, 2017

We discussed this in triage today, and the libs team is in favor of adding these methods to Ord

@Mark-Simulacrum
Copy link
Member

[De-nominating]

frewsxcv added a commit to frewsxcv/rust that referenced this issue Jun 13, 2017
…=BurntSushi

Add max and min to Ord

Pursuant to issue rust-lang#25663, this PR adds max and min methods with default implementations to std::cmp::Ord. It also modifies std::cmp::max|min to internally alias to Ord::max|min, so that any overrides of the default implementations are automatically used by std::cmp::max|min.

Closes rust-lang#25663
@sfackler sfackler reopened this Jun 21, 2017
@sfackler sfackler changed the title There's f64.min(), but no i64.min() Tracking issue for Ord::{min, max} Jun 21, 2017
@sfackler sfackler added B-unstable Blocker: Implemented in the nightly compiler and unstable. and removed I-papercut labels Jun 21, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Jul 22, 2017
@aturon
Copy link
Member

aturon commented Aug 29, 2017

We're pretty much committed to this.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Aug 29, 2017

Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, 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 the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Aug 29, 2017
@rfcbot
Copy link

rfcbot commented Sep 12, 2017

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

@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 Sep 12, 2017
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 15, 2017
alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 16, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 16, 2017
alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 17, 2017
@bors bors closed this as completed in 5398e03 Sep 17, 2017
dtolnay pushed a commit to dtolnay/rust that referenced this issue Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants