[PPL-devel] [GIT] ppl/ppl(floating_point): Converted helpers to work also for native numbers.
Abramo Bagnara
abramo.bagnara at gmail.com
Sat Sep 19 09:51:46 CEST 2009
Module: ppl/ppl
Branch: floating_point
Commit: 01dab9748259cee736256a446e6e7451bf0992c0
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=01dab9748259cee736256a446e6e7451bf0992c0
Author: Abramo Bagnara <abramo.bagnara at gmail.com>
Date: Sat Sep 19 09:51:20 2009 +0200
Converted helpers to work also for native numbers.
---
src/math_utilities.defs.hh | 25 ++++++++++++-------------
src/math_utilities.inlines.hh | 33 ++++++++++++++++-----------------
2 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/src/math_utilities.defs.hh b/src/math_utilities.defs.hh
index 2b082ce..be685c5 100644
--- a/src/math_utilities.defs.hh
+++ b/src/math_utilities.defs.hh
@@ -32,17 +32,17 @@ namespace Parma_Polyhedra_Library {
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
//! Extract the numerator and denominator components of \p from.
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
-template <typename T, typename Policy>
-void
-numer_denom(const Checked_Number<T, Policy>& from,
+template <typename T>
+typename Enable_If<Is_Native_Or_Checked<T>::value, void>::type
+numer_denom(const T& from,
Coefficient& num, Coefficient& den);
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
//! Divides \p x by \p y into \p to, rounding the result towards plus infinity.
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
-template <typename T, typename Policy>
-void
-div_round_up(Checked_Number<T, Policy>& to,
+template <typename T>
+typename Enable_If<Is_Native_Or_Checked<T>::value, void>::type
+div_round_up(T& to,
Coefficient_traits::const_reference x,
Coefficient_traits::const_reference y);
@@ -63,17 +63,16 @@ max_assign(N& x, const N& y);
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
//! Returns <CODE>true</CODE> if and only if \p x is an even number.
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
-template <typename T, typename Policy>
-bool
-is_even(const Checked_Number<T, Policy>& x);
+template <typename T>
+typename Enable_If<Is_Native_Or_Checked<T>::value, bool>::type
+is_even(const T& x);
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
//! Returns <CODE>true</CODE> if and only if \f$x = -y\f$.
#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
-template <typename T, typename Policy>
-bool
-is_additive_inverse(const Checked_Number<T, Policy>& x,
- const Checked_Number<T, Policy>& y);
+template <typename T>
+typename Enable_If<Is_Native_Or_Checked<T>::value, bool>::type
+is_additive_inverse(const T& x, const T& y);
#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
/*! \brief
diff --git a/src/math_utilities.inlines.hh b/src/math_utilities.inlines.hh
index 14b0f5f..dfa3fc6 100644
--- a/src/math_utilities.inlines.hh
+++ b/src/math_utilities.inlines.hh
@@ -46,9 +46,9 @@ low_bits_mask(const unsigned n) {
return n == 0 ? 0 : ~(~(T(0u)) << n);
}
-template <typename T, typename Policy>
-inline void
-numer_denom(const Checked_Number<T, Policy>& from,
+template <typename T>
+inline typename Enable_If<Is_Native_Or_Checked<T>::value, void>::type
+numer_denom(const T& from,
Coefficient& num, Coefficient& den) {
PPL_ASSERT(!is_not_a_number(from)
&& !is_minus_infinity(from)
@@ -59,9 +59,9 @@ numer_denom(const Checked_Number<T, Policy>& from,
den = q.get_den();
}
-template <typename T, typename Policy>
-inline void
-div_round_up(Checked_Number<T, Policy>& to,
+template <typename T>
+inline typename Enable_If<Is_Native_Or_Checked<T>::value, void>::type
+div_round_up(T& to,
Coefficient_traits::const_reference x,
Coefficient_traits::const_reference y) {
PPL_DIRTY_TEMP0(mpq_class, qx);
@@ -88,19 +88,18 @@ max_assign(N& x, const N& y) {
x = y;
}
-template <typename T, typename Policy>
-inline bool
-is_even(const Checked_Number<T, Policy>& x) {
- Checked_Number<T, Policy> half_x;
- return div_2exp_assign_r(half_x, x, 1, ROUND_DIRECT | ROUND_STRICT_RELATION) == V_EQ
- && is_integer(half_x);
+template <typename T>
+inline typename Enable_If<Is_Native_Or_Checked<T>::value, bool>::type
+is_even(const T& x) {
+ T mod;
+ return umod_2exp_assign_r(mod, x, 1, ROUND_DIRECT | ROUND_STRICT_RELATION) == V_EQ
+ && mod == 0;
}
-template <typename T, typename Policy>
-inline bool
-is_additive_inverse(const Checked_Number<T, Policy>& x,
- const Checked_Number<T, Policy>& y) {
- Checked_Number<T, Policy> negated_x;
+template <typename T>
+inline typename Enable_If<Is_Native_Or_Checked<T>::value, bool>::type
+is_additive_inverse(const T& x, const T& y) {
+ T negated_x;
return neg_assign_r(negated_x, x, ROUND_DIRECT | ROUND_STRICT_RELATION) == V_EQ
&& negated_x == y;
}
More information about the PPL-devel
mailing list