[PPL-devel] [GIT] ppl/ppl(floating_point): Added BASE field to floating point struct.

Fabio Biselli fabio.biselli at studenti.unipr.it
Fri Oct 16 11:57:22 CEST 2009


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

Author: Fabio Biselli <fabio.biselli at studenti.unipr.it>
Date:   Fri Oct 16 11:53:37 2009 +0200

Added BASE field to floating point struct.
Modified absolute/relative error definition using FP_Format::BASE.
Modified tests using FP_Format::BASE.

---

 src/Float.defs.hh                                  |    9 +++++++++
 src/Floating_Point_Expression.defs.hh              |   17 +++++++++++------
 src/Floating_Point_Expression.templates.hh         |   11 +++++++----
 tests/Floating_Point_Expression/Makefile.am        |    3 +--
 .../floatingpointexpr1.cc                          |   10 +++++-----
 5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/Float.defs.hh b/src/Float.defs.hh
index f0eb5f8..2030f55 100644
--- a/src/Float.defs.hh
+++ b/src/Float.defs.hh
@@ -49,6 +49,7 @@ struct float_ieee754_half {
   static const uint16_t NEG_INF = 0x7c00;
   static const uint16_t POS_ZERO = 0x0000;
   static const uint16_t NEG_ZERO = 0x8000;
+  static const unsigned int BASE = 2;
   static const unsigned int EXPONENT_BITS = 5;
   static const unsigned int MANTISSA_BITS = 10;
   static const int EXPONENT_MAX = (1 << (EXPONENT_BITS - 1)) - 1;
@@ -80,6 +81,7 @@ struct float_ieee754_single {
   static const uint32_t NEG_INF = 0xff800000;
   static const uint32_t POS_ZERO = 0x00000000;
   static const uint32_t NEG_ZERO = 0x80000000;
+  static const unsigned int BASE = 2;
   static const unsigned int EXPONENT_BITS = 8;
   static const unsigned int MANTISSA_BITS = 23;
   static const int EXPONENT_MAX = (1 << (EXPONENT_BITS - 1)) - 1;
@@ -124,6 +126,7 @@ struct float_ieee754_double {
   static const uint32_t LSP_INF = 0;
   static const uint32_t LSP_ZERO = 0;
   static const uint32_t LSP_MAX = 0xffffffff;
+  static const unsigned int BASE = 2;
   static const unsigned int EXPONENT_BITS = 11;
   static const unsigned int MANTISSA_BITS = 52;
   static const int EXPONENT_MAX = (1 << (EXPONENT_BITS - 1)) - 1;
@@ -154,6 +157,7 @@ struct float_ibm_single {
   static const uint32_t NEG_INF = 0xff000000;
   static const uint32_t POS_ZERO = 0x00000000;
   static const uint32_t NEG_ZERO = 0x80000000;
+  static const unsigned int BASE = 16;
   static const unsigned int EXPONENT_BITS = 7;
   static const unsigned int MANTISSA_BITS = 24;
   static const int EXPONENT_BIAS = 64;
@@ -177,6 +181,9 @@ struct float_ibm_single {
 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
 
 struct float_ibm_double {
+  // FIXME: BASE must be 16, 16^56 should return an overflow
+  // and absolute/relative error are not sound.
+  static const unsigned int BASE = 2;
   static const unsigned int EXPONENT_BITS = 7;
   static const unsigned int MANTISSA_BITS = 56;
   static const int EXPONENT_BIAS = 64;
@@ -203,6 +210,7 @@ struct float_intel_double_extended {
   static const uint64_t LSP_ZERO = 0;
   static const uint64_t LSP_DMAX = 0x7fffffffffffffffULL;
   static const uint64_t LSP_NMAX = 0xffffffffffffffffULL;
+  static const unsigned int BASE = 2;
   static const unsigned int EXPONENT_BITS = 15;
   static const unsigned int MANTISSA_BITS = 63;
   static const int EXPONENT_MAX = (1 << (EXPONENT_BITS - 1)) - 1;
@@ -241,6 +249,7 @@ struct float_ieee754_quad {
   static const uint64_t LSP_INF = 0;
   static const uint64_t LSP_ZERO = 0;
   static const uint64_t LSP_MAX = 0xffffffffffffffffULL;
+  static const unsigned int BASE = 2;
   static const unsigned int EXPONENT_BITS = 15;
   static const unsigned int MANTISSA_BITS = 112;
   static const int EXPONENT_MAX = (1 << (EXPONENT_BITS - 1)) - 1;
diff --git a/src/Floating_Point_Expression.defs.hh b/src/Floating_Point_Expression.defs.hh
index fb94f2d..a66190d 100644
--- a/src/Floating_Point_Expression.defs.hh
+++ b/src/Floating_Point_Expression.defs.hh
@@ -190,12 +190,17 @@ public:
 
 template <typename FP_Interval_Type, typename FP_Format>
 typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::boundary_type
-Floating_Point_Expression<FP_Interval_Type, FP_Format>::absolute_error =
-  std::max(
-       static_cast<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::boundary_type>
-       (pow(2, static_cast<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::boundary_type>(1) - FP_Format::EXPONENT_BIAS - FP_Format::MANTISSA_BITS))
-       ,
-       std::numeric_limits<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::boundary_type>::denorm_min());
+Floating_Point_Expression<FP_Interval_Type, FP_Format>::absolute_error = 
+std::max(
+  static_cast<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>
+  ::boundary_type>(pow(FP_Format::BASE, static_cast<typename 
+		       Floating_Point_Expression<FP_Interval_Type, FP_Format>
+		       ::boundary_type>(1) - FP_Format
+		       ::EXPONENT_BIAS - FP_Format
+		       ::MANTISSA_BITS)),
+  std::numeric_limits<typename 
+                      Floating_Point_Expression<FP_Interval_Type, FP_Format>
+  ::boundary_type>::denorm_min());
 
 } // namespace Parma_Polyhedra_Library
 
diff --git a/src/Floating_Point_Expression.templates.hh b/src/Floating_Point_Expression.templates.hh
index 0343bff..11168e0 100644
--- a/src/Floating_Point_Expression.templates.hh
+++ b/src/Floating_Point_Expression.templates.hh
@@ -35,9 +35,12 @@ Floating_Point_Expression<FP_Interval_Type, FP_Format>
 ::relative_error(const FP_Linear_Form& lf, FP_Linear_Form& result) {
   /* FIXME: here we assume that boundary_type can represent
      (2)^(-FP_Format::MANTISSA_BITS) precisely. */
-  FP_Interval_Type error_propagator(-pow(2, -static_cast<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::boundary_type>(FP_Format::MANTISSA_BITS)));
-  // FIXME: this may be incorrect for some policies.
-  error_propagator.join_assign(FP_Interval_Type(pow(2, -static_cast<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::boundary_type>(FP_Format::MANTISSA_BITS))));
+  FP_Interval_Type error_propagator(-pow(FP_Format::BASE, 
+  -static_cast<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>
+  ::boundary_type>(FP_Format::MANTISSA_BITS)));
+  error_propagator.join_assign(FP_Interval_Type(pow(FP_Format::BASE, 
+  -static_cast<typename Floating_Point_Expression<FP_Interval_Type, FP_Format>
+  ::boundary_type>(FP_Format::MANTISSA_BITS))));
 
   // Handle the inhomogeneous term.
   const FP_Interval_Type* current_term = &lf.inhomogeneous_term();
@@ -52,7 +55,7 @@ Floating_Point_Expression<FP_Interval_Type, FP_Format>
   for (dimension_type i = 0; i < dimension; ++i) {
     current_term = &lf.coefficient(Variable(i));
     current_multiplier = FP_Interval_Type(std::max(abs(current_term->lower()),
-						   abs(current_term->upper())));
+					       abs(current_term->upper())));
     current_result_term = FP_Linear_Form(Variable(i));
     current_result_term *= current_multiplier;
     current_result_term *= error_propagator;
diff --git a/tests/Floating_Point_Expression/Makefile.am b/tests/Floating_Point_Expression/Makefile.am
index 9755e4b..7096075 100644
--- a/tests/Floating_Point_Expression/Makefile.am
+++ b/tests/Floating_Point_Expression/Makefile.am
@@ -51,9 +51,8 @@ $(top_builddir)/src/libppl.la \
 @extra_libraries@
 
 ORIGINAL_TESTS = \
-digitalfilters1
+digitalfilters1 
 
-#digitalfilters1
 #bdshape2 \
 #bdshape1 \
 #floatingpointexpr1 \
diff --git a/tests/Floating_Point_Expression/floatingpointexpr1.cc b/tests/Floating_Point_Expression/floatingpointexpr1.cc
index c4322eb..c8facf4 100644
--- a/tests/Floating_Point_Expression/floatingpointexpr1.cc
+++ b/tests/Floating_Point_Expression/floatingpointexpr1.cc
@@ -101,7 +101,7 @@ test04() {
   Variable A(0);
   Variable B(1);
   FP_Linear_Form known_result = FP_Linear_Form(A);
-  ANALYZER_FP_FORMAT exp = pow(2,
+  ANALYZER_FP_FORMAT exp = pow(ANALYZED_FP_FORMAT::BASE,
     -static_cast<ANALYZER_FP_FORMAT>(ANALYZED_FP_FORMAT::MANTISSA_BITS));
   tmp = FP_Interval(1);
   tmp -= exp;
@@ -135,7 +135,7 @@ test05() {
   Variable A(0);
   Variable B(1);
   FP_Linear_Form known_result = FP_Linear_Form(A);
-  ANALYZER_FP_FORMAT exp = pow(2,
+  ANALYZER_FP_FORMAT exp = pow(ANALYZED_FP_FORMAT::BASE,
     -static_cast<ANALYZER_FP_FORMAT>(ANALYZED_FP_FORMAT::MANTISSA_BITS));
   tmp = FP_Interval(1);
   tmp -= exp;
@@ -169,7 +169,7 @@ test06() {
 
   tmp = FP_Interval(-FP_Expression::absolute_error);
   tmp.join_assign(FP_Expression::absolute_error);
-  ANALYZER_FP_FORMAT exp = pow(2,
+  ANALYZER_FP_FORMAT exp = pow(ANALYZED_FP_FORMAT::BASE,
     -static_cast<ANALYZER_FP_FORMAT>((ANALYZED_FP_FORMAT::MANTISSA_BITS-1)));
   FP_Interval coeff = FP_Interval(2);
   coeff -= exp;
@@ -202,7 +202,7 @@ test07() {
 
   tmp = FP_Interval(-FP_Expression::absolute_error);
   tmp.join_assign(FP_Expression::absolute_error);
-  ANALYZER_FP_FORMAT exp = pow(2,
+  ANALYZER_FP_FORMAT exp = pow(ANALYZED_FP_FORMAT::BASE,
     -static_cast<ANALYZER_FP_FORMAT>((ANALYZED_FP_FORMAT::MANTISSA_BITS+1)));
   FP_Interval coeff = FP_Interval(1 / 2.0);
   coeff -= exp;
@@ -234,7 +234,7 @@ test08() {
 
   Variable A(0);
   FP_Linear_Form known_result = FP_Linear_Form(A);
-  ANALYZER_FP_FORMAT exp = pow(2,
+  ANALYZER_FP_FORMAT exp = pow(ANALYZED_FP_FORMAT::BASE,
     -static_cast<ANALYZER_FP_FORMAT>((ANALYZED_FP_FORMAT::MANTISSA_BITS+1)));
   tmp = FP_Interval(-1 / 2.0);
   tmp -= exp;




More information about the PPL-devel mailing list