lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] svn commit: r1333646 - in /lucy/branches/0.3: ./ core/Lucy/Object/Num.c core/Lucy/Object/Num.cfh
Date Thu, 03 May 2012 21:55:21 GMT
Author: marvin
Date: Thu May  3 21:55:21 2012
New Revision: 1333646

URL: http://svn.apache.org/viewvc?rev=1333646&view=rev
Log:
Backport Num comparison fixes, minus tests.

Backport r1310747 by nwellnhof: "Rework Num_Compare_To"

Make sure that we never try to use floating point arithmetics when
comparing integers. This fixes comparison of Integer64 numbers with
themselves as a side effect.

Modified:
    lucy/branches/0.3/   (props changed)
    lucy/branches/0.3/core/Lucy/Object/Num.c
    lucy/branches/0.3/core/Lucy/Object/Num.cfh

Propchange: lucy/branches/0.3/
------------------------------------------------------------------------------
  Merged /lucy/trunk:r1310747

Modified: lucy/branches/0.3/core/Lucy/Object/Num.c
URL: http://svn.apache.org/viewvc/lucy/branches/0.3/core/Lucy/Object/Num.c?rev=1333646&r1=1333645&r2=1333646&view=diff
==============================================================================
--- lucy/branches/0.3/core/Lucy/Object/Num.c (original)
+++ lucy/branches/0.3/core/Lucy/Object/Num.c Thu May  3 21:55:21 2012
@@ -49,24 +49,6 @@ Num_equals(Num *self, Obj *other) {
     return true;
 }
 
-int32_t
-Num_compare_to(Num *self, Obj *other) {
-    Num *twin = (Num*)CERTIFY(other, NUM);
-    double f64_diff = Num_To_F64(self) - Num_To_F64(twin);
-    if (f64_diff) {
-        if (f64_diff < 0)      { return -1; }
-        else if (f64_diff > 0) { return 1;  }
-    }
-    else {
-        int64_t i64_diff = Num_To_I64(self) - Num_To_I64(twin);
-        if (i64_diff) {
-            if (i64_diff < 0)      { return -1; }
-            else if (i64_diff > 0) { return 1;  }
-        }
-    }
-    return 0;
-}
-
 /***************************************************************************/
 
 FloatNum*
@@ -75,6 +57,15 @@ FloatNum_init(FloatNum *self) {
     return (FloatNum*)Num_init((Num*)self);
 }
 
+int32_t
+FloatNum_compare_to(FloatNum *self, Obj *other) {
+    Num *twin = (Num*)CERTIFY(other, NUM);
+    double f64_diff = FloatNum_To_F64(self) - Num_To_F64(twin);
+    if (f64_diff < 0)      { return -1; }
+    else if (f64_diff > 0) { return 1;  }
+    return 0;
+}
+
 CharBuf*
 FloatNum_to_string(FloatNum *self) {
     return CB_newf("%f64", FloatNum_To_F64(self));
@@ -88,6 +79,18 @@ IntNum_init(IntNum *self) {
     return (IntNum*)Num_init((Num*)self);
 }
 
+int32_t
+IntNum_compare_to(IntNum *self, Obj *other) {
+    if (!Obj_Is_A(other, INTNUM)) {
+        return -Obj_Compare_To(other, (Obj*)self);
+    }
+    int64_t self_value  = IntNum_To_I64(self);
+    int64_t other_value = Obj_To_I64(other);
+    if (self_value < other_value)      { return -1; }
+    else if (self_value > other_value) { return 1;  }
+    return 0;
+}
+
 CharBuf*
 IntNum_to_string(IntNum *self) {
     return CB_newf("%i64", IntNum_To_I64(self));

Modified: lucy/branches/0.3/core/Lucy/Object/Num.cfh
URL: http://svn.apache.org/viewvc/lucy/branches/0.3/core/Lucy/Object/Num.cfh?rev=1333646&r1=1333645&r2=1333646&view=diff
==============================================================================
--- lucy/branches/0.3/core/Lucy/Object/Num.cfh (original)
+++ lucy/branches/0.3/core/Lucy/Object/Num.cfh Thu May  3 21:55:21 2012
@@ -25,9 +25,6 @@ abstract class Lucy::Object::Num inherit
 
     public bool_t
     Equals(Num *self, Obj *other);
-
-    public int32_t
-    Compare_To(Num *self, Obj *other);
 }
 
 /** Abstract base class for floating point numbers.
@@ -37,6 +34,9 @@ abstract class Lucy::Object::FloatNum in
     inert FloatNum*
     init(FloatNum *self);
 
+    public int32_t
+    Compare_To(FloatNum *self, Obj *other);
+
     public incremented CharBuf*
     To_String(FloatNum *self);
 }
@@ -49,6 +49,9 @@ abstract class Lucy::Object::IntNum inhe
     inert IntNum*
     init(IntNum *self);
 
+    public int32_t
+    Compare_To(IntNum *self, Obj *other);
+
     public incremented CharBuf*
     To_String(IntNum *self);
 }



Mime
View raw message