You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Alberto Leal, edA-qa mort-ora-y and Squirrel
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
-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.
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.
@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:
Activity
Aatch commentedon 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_minandpartial_maxfunctions for types that only implementPartialOrd.aturon commentedon May 21, 2015
+1 for an inherent method. I think this is just an oversight.
alexcrichton commentedon May 26, 2015
I believe @bluss commented to this effect already, but the idea here is that there is "one true
minmethod" atcmp::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::minnagisa commentedon 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,}, whilecmp::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 commentedon Dec 14, 2016
Ignoring the "many-ways-to-do-the-same problem" for a second, couldn't
minandmaxjust be generic 'provided methods' on theOrdtrait?kornelski commentedon Dec 14, 2016
For me this is a practical problem, because changing type needlessly changes syntax.
I can't change
a = 1; b = 2without 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
maxis one of the warts that doesn't.Mark-Simulacrum commentedon May 18, 2017
@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::Numberdoesn't implement min/max inherently, but should it?I think that the things that have been brought up are:
aturon commentedon May 23, 2017
We discussed this in triage today, and the libs team is in favor of adding these methods to
OrdMark-Simulacrum commentedon May 23, 2017
[De-nominating]
Rollup merge of rust-lang#42496 - Razaekel:feature/integer_max-min, r…
13 remaining items
stabilized ord_max_min (fixes rust-lang#25663)
Rollup merge of rust-lang#44593 - budziq:stabilize_ord_max_min, r=ale…
Rollup merge of rust-lang#44593 - budziq:stabilize_ord_max_min, r=ale…
Rollup merge of rust-lang#44593 - budziq:stabilize_ord_max_min, r=ale…
stabilized ord_max_min (fixes rust-lang#25663)
Auto merge of #161081 - scottmcm:min-max-intrinsics, r=clarfonthey
Auto merge of #161081 - scottmcm:min-max-intrinsics, r=clarfonthey
Auto merge of #161081 - scottmcm:min-max-intrinsics, r=clarfonthey
Auto merge of #161081 - scottmcm:min-max-intrinsics, r=clarfonthey
Auto merge of #161081 - scottmcm:min-max-intrinsics, r=clarfonthey
Auto merge of #161081 - scottmcm:min-max-intrinsics, r=clarfonthey