Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upstd::cmp::max vs std::num::Float vs NaN #21816
Comments
This comment has been minimized.
This comment has been minimized.
|
I personally think |
This comment has been minimized.
This comment has been minimized.
|
This issue should be moved to https://github.com/rust-lang/rfcs? Regarding your second suggestion, how would you implement Alternative: we could introduce an additional trait, implemented for Ord and f32, f64: trait Lattice : PartialOrd {
fn max(&self, other: &Self) -> Self;
fn min(&self, other: &Self) -> Self;
}
impl<T: Ord> Lattice for T { ... }
impl Lattice for f32 { ... }
impl Lattice for f64 { ... }
fn max<T: Lattice>(x: T, y: T) -> T { x.max(&y) }
fn min<T: Lattice>(x: T, y: T) -> T { x.min(&y) }The drawback is that, we need to introduce yet another comparison trait. @bombless Note that IEEE 754 defines |
kmcallister
added
the
A-libs
label
Feb 1, 2015
This comment has been minimized.
This comment has been minimized.
|
We have Float::max anyway, so I don't think IEEE 754 could be a real problem. |
This comment has been minimized.
This comment has been minimized.
|
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. As these functions are stable, changing them would require going through the RFC process. This issue has been moved to the RFCs repo: rust-lang/rfcs#852 |
kornelski commentedJan 31, 2015
It's werid that
std::cmp::maxcan't comparef64numbers. I know that strictly speaking IEEE floats don't have total order this function expects, but still it's surprising (andpartial_maxis awkward to use).And there's
std::num::Float::maxwhich works withf64just fine (the docs don't even say howNaNis handled).It bugs me that the two versions of
maxare not consistent in their strictness, and that the first-and-most-obviousmaxfunction in the stdlib "doesn't work" with a basic type in the language.My suggestion:
maxversion that only allowsOrdto something else, liketotal_maxorstrict_max.std::cmp::maxfor floating point numbers, so thata.max(b)is consistent withmax(a,b).