add correct floating point min and max methods.

The `std::cmp` functions are not correct for floating point types.

`min(NaN, 2.0)` and `min(2.0, NaN)` return different values, because
these functions assume a total order. Floating point types need special
`min`, `max` and `clamp` functions.
This commit is contained in:
Daniel Micay
2014-03-04 19:54:35 -05:00
parent 6e7f170fed
commit 2760974ec0
4 changed files with 25 additions and 3 deletions

View File

@@ -313,6 +313,9 @@ pub enum FPCategory {
pub trait Float: Signed
+ Round
+ Primitive {
fn max(self, other: Self) -> Self;
fn min(self, other: Self) -> Self;
// FIXME (#5527): These should be associated constants
fn nan() -> Self;
fn infinity() -> Self;