diff --git a/src/lib/float.rs b/src/lib/float.rs index 1b101eaf859b..c7053486ccb5 100644 --- a/src/lib/float.rs +++ b/src/lib/float.rs @@ -259,17 +259,39 @@ pure fn ge(x: float, y: float) -> bool { ret x >= y; } /* Predicate: gt */ pure fn gt(x: float, y: float) -> bool { ret x > y; } -/* Predicate: positive */ +/* +Predicate: positive + +Returns true if `x` is a positive number, including +0.0 and +Infinity. + */ pure fn positive(x: float) -> bool { ret x > 0. || (1./x) == infinity(); } -/* Predicate: negative */ +/* +Predicate: negative + +Returns true if `x` is a negative number, including -0.0 and -Infinity. + */ pure fn negative(x: float) -> bool { ret x < 0. || (1./x) == neg_infinity(); } -/* Predicate: nonpositive */ -pure fn nonpositive(x: float) -> bool { ret !positive(x); } +/* +Predicate: nonpositive -/* Predicate: nonnegative */ -pure fn nonnegative(x: float) -> bool { ret !negative(x); } +Returns true if `x` is a negative number, including -0.0 and -Infinity. +(This is the same as `float::negative`.) +*/ +pure fn nonpositive(x: float) -> bool { + ret x < 0. || (1./x) == neg_infinity(); +} + +/* +Predicate: nonnegative + +Returns true if `x` is a positive number, including +0.0 and +Infinity. +(This is the same as `float::positive`.) +*/ +pure fn nonnegative(x: float) -> bool { + ret x > 0. || (1./x) == infinity(); +} // // Local Variables: diff --git a/src/test/stdtest/float.rs b/src/test/stdtest/float.rs index 302d6b1679e0..d9de78b60090 100644 --- a/src/test/stdtest/float.rs +++ b/src/test/stdtest/float.rs @@ -47,7 +47,7 @@ fn test_nonpositive() { assert(float::nonpositive(-1.)); assert(float::nonpositive(float::neg_infinity())); assert(float::nonpositive(1./float::neg_infinity())); - // TODO: assert(!float::nonpositive(float::NaN())); + assert(!float::nonpositive(float::NaN())); } #[test] @@ -58,5 +58,5 @@ fn test_nonnegative() { assert(!float::nonnegative(-1.)); assert(!float::nonnegative(float::neg_infinity())); assert(!float::nonnegative(1./float::neg_infinity())); - // TODO: assert(!float::nonnegative(float::NaN())); + assert(!float::nonnegative(float::NaN())); }