From 45d77779916a7af0b2b7656453e31eea9f4b3cfa Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 27 Oct 2011 17:45:04 -0700 Subject: [PATCH] Change behavior of float::nonpositive/nonnegative Rather than being defined as !positive and !negative, these should act the same as negative and positive (respectively). The only effect of this change should be that all four functions will now return false for NaN. --- src/lib/float.rs | 34 ++++++++++++++++++++++++++++------ src/test/stdtest/float.rs | 4 ++-- 2 files changed, 30 insertions(+), 8 deletions(-) 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())); }