about summary refs log tree commit diff
path: root/src/libstd/num/mod.rs
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2014-03-04 19:54:35 -0500
committerDaniel Micay <danielmicay@gmail.com>2014-03-05 11:20:50 -0500
commit2760974ec05966c811f1ee6f85bf59b13f28b009 (patch)
tree68d84ba69516afbecb642ad7cb9074292df3dbbd /src/libstd/num/mod.rs
parent6e7f170fedd3c526a643c0b2d13863acd982be02 (diff)
downloadrust-2760974ec05966c811f1ee6f85bf59b13f28b009.tar.gz
rust-2760974ec05966c811f1ee6f85bf59b13f28b009.zip
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.
Diffstat (limited to 'src/libstd/num/mod.rs')
-rw-r--r--src/libstd/num/mod.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs
index 2051eeef60c..2f377a52ef8 100644
--- a/src/libstd/num/mod.rs
+++ b/src/libstd/num/mod.rs
@@ -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;