Skip to content

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

Closed

Description

@kornelski

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.

Activity

  1. Aatch commented on May 21, 2015

    @Aatch
    Contributor

    @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.

  2. aturon commented on May 21, 2015

    @aturon
    Contributor

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

  3. alexcrichton commented on May 26, 2015

    @alexcrichton
    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

  4. nagisa commented on Jun 17, 2015

    @nagisa
    Member

    -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.

  5. frewsxcv commented on Dec 14, 2016

    @frewsxcv
    Contributor

    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?

  6. kornelski commented on Dec 14, 2016

    @kornelski
    ContributorAuthor

    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.

  7. Mark-Simulacrum commented on May 18, 2017

    @Mark-Simulacrum
    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:

  8. aturon commented on May 23, 2017

    @aturon
    Contributor

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

  9. Mark-Simulacrum commented on May 23, 2017

    @Mark-Simulacrum
    Member

    [De-nominating]

  10. added a commit that references this issue on Jun 13, 2017
  11. 13 remaining items

  12. added a commit that references this issue on Sep 15, 2017
    5398e03
  13. added a commit that references this issue on Sep 15, 2017
    5e9b68f
  14. added a commit that references this issue on Sep 16, 2017
    adc0961
  15. added a commit that references this issue on Sep 16, 2017
    1ae6ab4
  16. added a commit that references this issue on Sep 25, 2017
    df8fec1
  17. added 5 commits that reference this issue on Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions