Skip to content

Commit 45d7777

Browse files
mbrubeckbrson
authored andcommitted
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.
1 parent 000b2fe commit 45d7777

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/lib/float.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,39 @@ pure fn ge(x: float, y: float) -> bool { ret x >= y; }
259259
/* Predicate: gt */
260260
pure fn gt(x: float, y: float) -> bool { ret x > y; }
261261

262-
/* Predicate: positive */
262+
/*
263+
Predicate: positive
264+
265+
Returns true if `x` is a positive number, including +0.0 and +Infinity.
266+
*/
263267
pure fn positive(x: float) -> bool { ret x > 0. || (1./x) == infinity(); }
264268

265-
/* Predicate: negative */
269+
/*
270+
Predicate: negative
271+
272+
Returns true if `x` is a negative number, including -0.0 and -Infinity.
273+
*/
266274
pure fn negative(x: float) -> bool { ret x < 0. || (1./x) == neg_infinity(); }
267275

268-
/* Predicate: nonpositive */
269-
pure fn nonpositive(x: float) -> bool { ret !positive(x); }
276+
/*
277+
Predicate: nonpositive
278+
279+
Returns true if `x` is a negative number, including -0.0 and -Infinity.
280+
(This is the same as `float::negative`.)
281+
*/
282+
pure fn nonpositive(x: float) -> bool {
283+
ret x < 0. || (1./x) == neg_infinity();
284+
}
270285

271-
/* Predicate: nonnegative */
272-
pure fn nonnegative(x: float) -> bool { ret !negative(x); }
286+
/*
287+
Predicate: nonnegative
288+
289+
Returns true if `x` is a positive number, including +0.0 and +Infinity.
290+
(This is the same as `float::positive`.)
291+
*/
292+
pure fn nonnegative(x: float) -> bool {
293+
ret x > 0. || (1./x) == infinity();
294+
}
273295

274296
//
275297
// Local Variables:

src/test/stdtest/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn test_nonpositive() {
4747
assert(float::nonpositive(-1.));
4848
assert(float::nonpositive(float::neg_infinity()));
4949
assert(float::nonpositive(1./float::neg_infinity()));
50-
// TODO: assert(!float::nonpositive(float::NaN()));
50+
assert(!float::nonpositive(float::NaN()));
5151
}
5252

5353
#[test]
@@ -58,5 +58,5 @@ fn test_nonnegative() {
5858
assert(!float::nonnegative(-1.));
5959
assert(!float::nonnegative(float::neg_infinity()));
6060
assert(!float::nonnegative(1./float::neg_infinity()));
61-
// TODO: assert(!float::nonnegative(float::NaN()));
61+
assert(!float::nonnegative(float::NaN()));
6262
}

0 commit comments

Comments
 (0)