-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
cmp: min/max is inconsistent with partial_min/max on certain edge cases #23687
Comments
Additionally, there is inconsistency between cmp::min/max and foo.iter().min/max as can be seen here: http://is.gd/aSAlz0 It should be mentioned that the author of It would be nice to get this consistent across the board. cc @aturon |
I agree that these should be made consistent; I don't think it requires a full RFC to do so. I had also heard that bit of wisdom from the STL, suggesting that the |
To be explicit: The hindsight from STL as I understand it is that Currently our |
Yeah I also think that this is fine to change without an RFC, and I also don't mind going with what the accepted way should be. |
`min`-like functions now return the leftmost element/input for equal elements. `max`-like return the rightmost. Closes rust-lang#23687. cc @HeroesGrave, @aturon, @alexcrichton
cmp::partial_min(a, b)
returns a if a <= b, whilecmp::min(a, b)
return a if a < b.Same story with
partial_/max
.This will cause unexpected behaviour when
a < b == a > b == false
, buta != b
(ie: ord treats them as equal, but they aren't equal). For simple types this isn't an issue because if ord treats them as equal they are usually equal. However, for more complex types,partial_min(a, b) != min(a, b)
etc. which will cause subtle errors and a lot of pain tracking down the cause.The behaviour of the
partial_
variants in this case seems more correct to me. When the two arguments are equal, it is more intuitive to return the first.Not sure if this needs an RFC to go through.
The text was updated successfully, but these errors were encountered: