[GIT] ppl/ppl(bounded_arithmetic): Added Bounded_Integer_Coefficient_Policy .
Module: ppl/ppl Branch: bounded_arithmetic Commit: a8f95c123cd384619f2be9584dad762930352426 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=a8f95c123cd38...
Author: Roberto Bagnara bagnara@cs.unipr.it Date: Wed May 13 20:00:32 2009 +0200
Added Bounded_Integer_Coefficient_Policy.
---
src/Coefficient.inlines.hh | 13 +++++- src/Coefficient.types.hh | 90 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 6 deletions(-)
diff --git a/src/Coefficient.inlines.hh b/src/Coefficient.inlines.hh index 1e02b8a..4a7f68b 100644 --- a/src/Coefficient.inlines.hh +++ b/src/Coefficient.inlines.hh @@ -25,6 +25,15 @@ site: http://www.cs.unipr.it/ppl/ . */
namespace Parma_Polyhedra_Library {
+#ifdef PPL_CHECKED_INTEGERS +inline void +Bounded_Integer_Coefficient_Policy::handle_result(Result r) { + if (result_overflow(r)) + throw_result_exception(r); +} +#endif // PPL_CHECKED_INTEGERS + + #if defined(PPL_CHECKED_INTEGERS) || defined(PPL_NATIVE_INTEGERS) inline Coefficient_traits::const_reference Coefficient_zero() { @@ -39,7 +48,7 @@ Coefficient_one() { static Coefficient one(1); return one; } -#endif +#endif // defined(PPL_CHECKED_INTEGERS) || defined(PPL_NATIVE_INTEGERS)
#ifdef PPL_GMP_INTEGERS inline Coefficient_traits::const_reference @@ -54,7 +63,7 @@ Coefficient_one() { assert(*Coefficient_one_p != 0); return *Coefficient_one_p; } -#endif +#endif // PPL_GMP_INTEGERS
} // namespace Parma_Polyhedra_Library
diff --git a/src/Coefficient.types.hh b/src/Coefficient.types.hh index bb4f7d1..f785663 100644 --- a/src/Coefficient.types.hh +++ b/src/Coefficient.types.hh @@ -18,6 +18,88 @@ PURPOSE. */
namespace Parma_Polyhedra_Library {
+//! A policy for checked bounded integer coefficients. +/*! \ingroup PPL_CXX_interface */ +struct Bounded_Integer_Coefficient_Policy { + //! Check for overflowed result. + const_bool_nodef(check_overflow, true); + + //! Do not check for attempts to add infinities with different sign. + const_bool_nodef(check_inf_add_inf, false); + + //! Do not check for attempts to subtract infinities with same sign. + const_bool_nodef(check_inf_sub_inf, false); + + //! Do not check for attempts to multiply infinities by zero. + const_bool_nodef(check_inf_mul_zero, false); + + //! Do not check for attempts to divide by zero. + const_bool_nodef(check_div_zero, false); + + //! Do not check for attempts to divide infinities. + const_bool_nodef(check_inf_div_inf, false); + + //! Do not check for attempts to compute remainder of infinities. + const_bool_nodef(check_inf_mod, false); + + //! Do not checks for attempts to take the square root of a negative number. + const_bool_nodef(check_sqrt_neg, false); + + //! Do not handle not-a-number special value. + const_bool_nodef(has_nan, false); + + //! Handle infinity special values if \p T have them. + const_bool_nodef(has_infinity, false); + + /*! \brief + The checked number can always be safely converted to the + underlying type \p T and vice-versa. + */ + const_bool_nodef(convertible, true); + + //! Do not honor requests to check for FPU inexact results. + const_bool_nodef(fpu_check_inexact, false); + + //! Do not make extra checks to detect FPU NaN results. + const_bool_nodef(check_nan_result, true); + + /*! \brief + For constructors, by default use the same rounding used by + underlying type. + */ + static const Rounding_Dir ROUND_DEFAULT_CONSTRUCTOR = ROUND_NATIVE; + + /*! \brief + For overloaded operators (operator+(), operator-(), ...), by + default use the same rounding used by the underlying type. + */ + static const Rounding_Dir ROUND_DEFAULT_OPERATOR = ROUND_NATIVE; + + /*! \brief + For input functions, by default use the same rounding used by + the underlying type. + */ + static const Rounding_Dir ROUND_DEFAULT_INPUT = ROUND_NATIVE; + + /*! \brief + For output functions, by default use the same rounding used by + the underlying type. + */ + static const Rounding_Dir ROUND_DEFAULT_OUTPUT = ROUND_NATIVE; + + /*! \brief + For all other functions, by default use the same rounding used by + the underlying type. + */ + static const Rounding_Dir ROUND_DEFAULT_FUNCTION = ROUND_NATIVE; + + /*! \brief + Handles \p r: called by all constructors, operators and functions that + do not return a Result value. + */ + static void handle_result(Result r); +}; + #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS //! Coefficient traits specialization for 8 bits checked integers. /*! \ingroup PPL_CXX_interface */ @@ -72,14 +154,14 @@ namespace Parma_Polyhedra_Library { /*! \ingroup PPL_CXX_interface Objects of type Coefficient are used to implement the integral valued coefficients occurring in linear expressions, constraints, generators, - intervals, bounding boxes and so on. Depending on the chosen + intervals, bounding boxes and so on. Depending on the chosen configuration options (see file <CODE>README.configure</CODE>), a Coefficient may actually be: - The GMP_Integer type, which in turn is an alias for the <CODE>mpz_class</CODE> type implemented by the C++ interface - of the GMP library (this is the default configuration); - - An instance of the Checked_Number class template: with its default - policy (Checked_Number_Default_Policy), this implements overflow + of the GMP library (this is the default configuration). + - An instance of the Checked_Number class template: with the policy + Bounded_Integer_Coefficient_Policy, this implements overflow detection on top of a native integral type (available template instances include checked integers having 8, 16, 32 or 64 bits); with the Checked_Number_Transparent_Policy, this is a wrapper
participants (1)
-
Roberto Bagnara