[PPL-devel] [GIT] ppl/ppl(floating_point): Fixed a bug in Linar_Form::operator== where zero coefficients were not

Fabio Bossi bossi at cs.unipr.it
Mon Sep 7 14:22:43 CEST 2009


Module: ppl/ppl
Branch: floating_point
Commit: bf7c1eb0d35ea326d3af8c04623596826baf7e41
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=bf7c1eb0d35ea326d3af8c04623596826baf7e41

Author: Fabio Bossi <bossi at cs.unipr.it>
Date:   Mon Sep  7 14:23:23 2009 +0200

Fixed a bug in Linar_Form::operator== where zero coefficients were not
treated properly. Added a few simple tests for class
Floating_Point_Expression.

---

 src/Linear_Form.templates.hh                       |   24 ++++++++--
 .../floatingpointexpr1.cc                          |   48 ++++++++++++++++++-
 2 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/src/Linear_Form.templates.hh b/src/Linear_Form.templates.hh
index 19dc331..ffa6772 100644
--- a/src/Linear_Form.templates.hh
+++ b/src/Linear_Form.templates.hh
@@ -325,12 +325,26 @@ inline bool
 operator==(const Linear_Form<C>& x, const Linear_Form<C>& y) {
   const dimension_type x_size = x.size();
   const dimension_type y_size = y.size();
-  if (x_size != y_size)
-    return false;
+  if (x_size >= y_size) {
+    for (dimension_type i = y_size; i-- > 0; )
+      if (x[i] != y[i])
+        return false;
 
-  for (dimension_type i = x_size; i-- > 0; )
-    if (x[i] != y[i])
-      return false;
+    for (dimension_type i = x_size; --i > y_size; )
+      if (x[i] != x.zero)
+        return false;
+
+  }
+  else {
+    for (dimension_type i = x_size; i-- > 0; )
+      if (x[i] != y[i])
+        return false;
+
+    for (dimension_type i = y_size; --i > x_size; )
+      if (y[i] != x.zero)
+        return false;
+
+  }
 
   return true;
 }
diff --git a/tests/Floating_Point_Expression/floatingpointexpr1.cc b/tests/Floating_Point_Expression/floatingpointexpr1.cc
index e0cf4e1..2e0e303 100644
--- a/tests/Floating_Point_Expression/floatingpointexpr1.cc
+++ b/tests/Floating_Point_Expression/floatingpointexpr1.cc
@@ -97,11 +97,11 @@ test02() {
 bool
 test03() {
   con_fpess* num = new con_fpess(3, 5);
-  con_fpess* den = new con_fpess(-1,1);
+  con_fpess* den = new con_fpess(-1, 1);
   div_fpess div(num, den);
   try {
-    Float_Interval_Linear_Form res;
-    div.linearize(sstr(), res);
+    Float_Interval_Linear_Form result;
+    div.linearize(sstr(), result);
   }
   catch (Linearization_Failed e) {
     return true;
@@ -109,10 +109,52 @@ test03() {
   return false;
 }
 
+bool
+test04() {
+  sstr store;
+  store[0] = fl_r_oc(0);
+  store[1] = fl_r_oc(10);
+  con_fpess* con = new con_fpess(5, 6);
+  var_fpess* var0 = new var_fpess(0);
+  var_fpess* var1 = new var_fpess(1);
+  dif_fpess* dif = new dif_fpess(var1, con);
+  mul_fpess mul(dif, var0);
+  Float_Interval_Linear_Form result;
+  mul.linearize(store, result);
+  nout << result << endl;
+  fl_r_oc kr(-std::numeric_limits<float>::denorm_min());
+  kr.join_assign(std::numeric_limits<float>::denorm_min());
+  Float_Interval_Linear_Form known_result(kr);
+  nout << known_result << endl;
+  return result == known_result;
+}
+
+bool
+test05() {
+  dstr store;
+  store[0] = db_r_oc(0);
+  store[1] = db_r_oc(4);
+  con_fpedd* con = new con_fpedd(5, 6);
+  var_fpedd* var0 = new var_fpedd(0);
+  var_fpedd* var1 = new var_fpedd(1);
+  sum_fpedd* sum = new sum_fpedd(con, var1);
+  mul_fpedd mul(var0, sum);
+  Double_Interval_Linear_Form result;
+  mul.linearize(store, result);
+  nout << result << endl;
+  db_r_oc kr(-std::numeric_limits<double>::denorm_min());
+  kr.join_assign(std::numeric_limits<double>::denorm_min());
+  Double_Interval_Linear_Form known_result(kr);
+  nout << known_result << endl;
+  return result == known_result;
+}
+
 } // namespace
 
 BEGIN_MAIN
   DO_TEST(test01);
   DO_TEST(test02);
   DO_TEST(test03);
+  DO_TEST(test04);
+  DO_TEST(test05);
 END_MAIN




More information about the PPL-devel mailing list