[PPL-devel] [GIT] ppl/ppl(floating_point): Do not add errors after rounding to a less precise format.

Fabio Bossi bossi at cs.unipr.it
Fri Jul 30 17:04:52 CEST 2010


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

Author: Fabio Bossi <bossi at cs.unipr.it>
Date:   Fri Jul 30 17:04:16 2010 +0200

Do not add errors after rounding to a less precise format.

---

 src/Float.defs.hh |    6 ++++++
 src/linearize.hh  |    5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/Float.defs.hh b/src/Float.defs.hh
index 75d2c2b..219e7d3 100644
--- a/src/Float.defs.hh
+++ b/src/Float.defs.hh
@@ -58,6 +58,7 @@ struct float_ieee754_half {
   static const int EXPONENT_MIN = -EXPONENT_MAX + 1;
   static const int EXPONENT_MIN_DENORM = EXPONENT_MIN
 					- static_cast<int>(MANTISSA_BITS);
+  static const Floating_Point_Format floating_point_format = IEEE754_HALF;
   int is_inf() const;
   int is_nan() const;
   int is_zero() const;
@@ -90,6 +91,7 @@ struct float_ieee754_single {
   static const int EXPONENT_MIN = -EXPONENT_MAX + 1;
   static const int EXPONENT_MIN_DENORM = EXPONENT_MIN
 					- static_cast<int>(MANTISSA_BITS);
+  static const Floating_Point_Format floating_point_format = IEEE754_SINGLE;
   int is_inf() const;
   int is_nan() const;
   int is_zero() const;
@@ -135,6 +137,7 @@ struct float_ieee754_double {
   static const int EXPONENT_MIN = -EXPONENT_MAX + 1;
   static const int EXPONENT_MIN_DENORM = EXPONENT_MIN
 					- static_cast<int>(MANTISSA_BITS);
+  static const Floating_Point_Format floating_point_format = IEEE754_DOUBLE;
   int is_inf() const;
   int is_nan() const;
   int is_zero() const;
@@ -166,6 +169,7 @@ struct float_ibm_single {
   static const int EXPONENT_MIN = -EXPONENT_MAX + 1;
   static const int EXPONENT_MIN_DENORM = EXPONENT_MIN
 					- static_cast<int>(MANTISSA_BITS);
+  static const Floating_Point_Format floating_point_format = IBM_SINGLE;
   int is_inf() const;
   int is_nan() const;
   int is_zero() const;
@@ -217,6 +221,8 @@ struct float_intel_double_extended {
   static const int EXPONENT_MIN = -EXPONENT_MAX + 1;
   static const int EXPONENT_MIN_DENORM = EXPONENT_MIN
 					- static_cast<int>(MANTISSA_BITS);
+  static const Floating_Point_Format floating_point_format =
+                                     INTEL_DOUBLE_EXTENDED;
   int is_inf() const;
   int is_nan() const;
   int is_zero() const;
diff --git a/src/linearize.hh b/src/linearize.hh
index 0093586..d21e5cb 100644
--- a/src/linearize.hh
+++ b/src/linearize.hh
@@ -629,8 +629,9 @@ cast_linearize(const Cast_Operator<Target>& cast_expr,
   }
   else {
     result = FP_Linear_Form(FP_Interval_Type(cast_arg->get_integer_interval()));
-    /* FIXME: we can avoid adding errors if FP_Interval_Type::boundary_type
-       is less precise than analyzed_format. */
+    if (is_less_precise_than(Float<analyzer_format>::Binary::floating_point_format, analyzed_format))
+      // We are rounding to a less precise format. Do not add errors.
+      return true;
   }
 
   FP_Linear_Form rel_error;




More information about the PPL-devel mailing list