about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Williams <peter@newton.cx>2013-01-12 18:48:19 -0500
committerTim Chevalier <chevalier@alum.wellesley.edu>2013-01-13 14:32:34 -0800
commitd5dc66ad3181ab4fa5fc3ccd806b25f3e5ddbe8f (patch)
tree01a15da2eb0491d7e02742317884200a15b3f14c
parent7eae397e58641392c20b4baefb39257264f7dcde (diff)
downloadrust-d5dc66ad3181ab4fa5fc3ccd806b25f3e5ddbe8f.tar.gz
rust-d5dc66ad3181ab4fa5fc3ccd806b25f3e5ddbe8f.zip
core: Align cmp::le() with the other implementations
Also add comments reminding that IEEE 754 requires unusual semantics for
comparison operators as applied to NaNs (x != x, if x = NaN), in case someone
in the future wants to get clever.
-rw-r--r--src/libcore/cmp.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs
index 141b6f19ab4..05dc74fb3c8 100644
--- a/src/libcore/cmp.rs
+++ b/src/libcore/cmp.rs
@@ -30,7 +30,10 @@ and `Eq` to overload the `==` and `!=` operators.
 *
 * Eventually this may be simplified to only require
 * an `eq` method, with the other generated from
-* a default implementation.
+* a default implementation. However it should
+* remain possible to implement `ne` separately, for
+* compatibility with floating-point NaN semantics
+* (cf. IEEE 754-2008 section 5.11).
 */
 #[lang="eq"]
 pub trait Eq {
@@ -43,7 +46,10 @@ pub trait Eq {
 *
 * Eventually this may be simplified to only require
 * an `le` method, with the others generated from
-* default implementations.
+* default implementations. However it should remain
+* possible to implement the others separately, for
+* compatibility with floating-point NaN semantics
+* (cf. IEEE 754-2008 section 5.11).
 */
 #[lang="ord"]
 pub trait Ord {
@@ -59,8 +65,8 @@ pub pure fn lt<T: Ord>(v1: &T, v2: &T) -> bool {
 }
 
 #[inline(always)]
-pub pure fn le<T: Ord Eq>(v1: &T, v2: &T) -> bool {
-    (*v1).lt(v2) || (*v1).eq(v2)
+pub pure fn le<T: Ord>(v1: &T, v2: &T) -> bool {
+    (*v1).le(v2)
 }
 
 #[inline(always)]