Skip to content

Commit 7e064de

Browse files
mbrubeckbrson
authored andcommitted
+0.0 should be positive and -0.0 should be negative.
1 parent 54ddb55 commit 7e064de

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/lib/float.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ fn NaN() -> float {
214214
}
215215

216216
/* Function: infinity */
217-
fn infinity() -> float {
217+
pure fn infinity() -> float {
218218
ret 1./0.;
219219
}
220220

221221
/* Function: neg_infinity */
222-
fn neg_infinity() -> float {
222+
pure fn neg_infinity() -> float {
223223
ret -1./0.;
224224
}
225225

@@ -257,16 +257,16 @@ pure fn ge(x: float, y: float) -> bool { ret x >= y; }
257257
pure fn gt(x: float, y: float) -> bool { ret x > y; }
258258

259259
/* Predicate: positive */
260-
pure fn positive(x: float) -> bool { ret x > 0.; }
260+
pure fn positive(x: float) -> bool { ret x > 0. || (1./x) == infinity(); }
261261

262262
/* Predicate: negative */
263-
pure fn negative(x: float) -> bool { ret x < 0.; }
263+
pure fn negative(x: float) -> bool { ret x < 0. || (1./x) == neg_infinity(); }
264264

265265
/* Predicate: nonpositive */
266-
pure fn nonpositive(x: float) -> bool { ret x <= 0.; }
266+
pure fn nonpositive(x: float) -> bool { ret !positive(x); }
267267

268268
/* Predicate: nonnegative */
269-
pure fn nonnegative(x: float) -> bool { ret x >= 0.; }
269+
pure fn nonnegative(x: float) -> bool { ret !negative(x); }
270270

271271
//
272272
// Local Variables:

src/test/stdtest/float.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,24 @@ fn test_from_str() {
1515
assert ( float::from_str("5.") == 5. );
1616
assert ( float::from_str(".5") == 0.5 );
1717
assert ( float::from_str("0.5") == 0.5 );
18+
}
1819

20+
#[test]
21+
fn test_positive() {
22+
assert(float::positive(float::infinity()));
23+
assert(float::positive(1.));
24+
assert(float::positive(0.));
25+
assert(!float::positive(-1.));
26+
assert(!float::positive(float::neg_infinity()));
27+
assert(!float::positive(1./float::neg_infinity()));
28+
}
29+
30+
#[test]
31+
fn test_negative() {
32+
assert(!float::negative(float::infinity()));
33+
assert(!float::negative(1.));
34+
assert(!float::negative(0.));
35+
assert(float::negative(-1.));
36+
assert(float::negative(float::neg_infinity()));
37+
assert(float::negative(1./float::neg_infinity()));
1938
}

0 commit comments

Comments
 (0)