about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2011-10-27 16:22:16 -0700
committerBrian Anderson <banderson@mozilla.com>2011-10-28 14:44:39 -0700
commit7e064deacfc9eab6e79737bb1f5070a19e2e1dc1 (patch)
treed2fc1b5654839d3d5973b4f8a4fa787c651257bb /src
parent54ddb553c2dab521f4d3bdf45e70767a413852d3 (diff)
downloadrust-7e064deacfc9eab6e79737bb1f5070a19e2e1dc1.tar.gz
rust-7e064deacfc9eab6e79737bb1f5070a19e2e1dc1.zip
+0.0 should be positive and -0.0 should be negative.
Diffstat (limited to 'src')
-rw-r--r--src/lib/float.rs12
-rw-r--r--src/test/stdtest/float.rs19
2 files changed, 25 insertions, 6 deletions
diff --git a/src/lib/float.rs b/src/lib/float.rs
index 5bdf250069e..55ffa5025e7 100644
--- a/src/lib/float.rs
+++ b/src/lib/float.rs
@@ -214,12 +214,12 @@ fn NaN() -> float {
 }
 
 /* Function: infinity */
-fn infinity() -> float {
+pure fn infinity() -> float {
    ret 1./0.;
 }
 
 /* Function: neg_infinity */
-fn neg_infinity() -> float {
+pure fn neg_infinity() -> float {
    ret -1./0.;
 }
 
@@ -257,16 +257,16 @@ pure fn ge(x: float, y: float) -> bool { ret x >= y; }
 pure fn gt(x: float, y: float) -> bool { ret x > y; }
 
 /* Predicate: positive */
-pure fn positive(x: float) -> bool { ret x > 0.; }
+pure fn positive(x: float) -> bool { ret x > 0. || (1./x) == infinity(); }
 
 /* Predicate: negative */
-pure fn negative(x: float) -> bool { ret x < 0.; }
+pure fn negative(x: float) -> bool { ret x < 0. || (1./x) == neg_infinity(); }
 
 /* Predicate: nonpositive */
-pure fn nonpositive(x: float) -> bool { ret x <= 0.; }
+pure fn nonpositive(x: float) -> bool { ret !positive(x); }
 
 /* Predicate: nonnegative */
-pure fn nonnegative(x: float) -> bool { ret x >= 0.; }
+pure fn nonnegative(x: float) -> bool { ret !negative(x); }
 
 //
 // Local Variables:
diff --git a/src/test/stdtest/float.rs b/src/test/stdtest/float.rs
index b77d83eb757..086942fb8c1 100644
--- a/src/test/stdtest/float.rs
+++ b/src/test/stdtest/float.rs
@@ -15,5 +15,24 @@ fn test_from_str() {
    assert ( float::from_str("5.") == 5. );
    assert ( float::from_str(".5") == 0.5 );
    assert ( float::from_str("0.5") == 0.5 );
+}
 
+#[test]
+fn test_positive() {
+  assert(float::positive(float::infinity()));
+  assert(float::positive(1.));
+  assert(float::positive(0.));
+  assert(!float::positive(-1.));
+  assert(!float::positive(float::neg_infinity()));
+  assert(!float::positive(1./float::neg_infinity()));
+}
+
+#[test]
+fn test_negative() {
+  assert(!float::negative(float::infinity()));
+  assert(!float::negative(1.));
+  assert(!float::negative(0.));
+  assert(float::negative(-1.));
+  assert(float::negative(float::neg_infinity()));
+  assert(float::negative(1./float::neg_infinity()));
 }