From d5dc66ad3181ab4fa5fc3ccd806b25f3e5ddbe8f Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Sat, 12 Jan 2013 18:48:19 -0500 Subject: [PATCH] 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. --- src/libcore/cmp.rs | 14 ++++++++++---- 1 file 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(v1: &T, v2: &T) -> bool { } #[inline(always)] -pub pure fn le(v1: &T, v2: &T) -> bool { - (*v1).lt(v2) || (*v1).eq(v2) +pub pure fn le(v1: &T, v2: &T) -> bool { + (*v1).le(v2) } #[inline(always)]