Skip to content

Commit

Permalink
core: Align cmp::le() with the other implementations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pkgw authored and catamorphism committed Jan 13, 2013
1 parent 7eae397 commit d5dc66a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/libcore/cmp.rs
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)]
Expand Down

0 comments on commit d5dc66a

Please sign in to comment.