1 /* Declarations of some math utility functions. 2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com) 4 5 This file is part of the Parma Polyhedra Library (PPL). 6 7 The PPL is free software; you can redistribute it and/or modify it 8 under the terms of the GNU General Public License as published by the 9 Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 The PPL is distributed in the hope that it will be useful, but WITHOUT 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software Foundation, 19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 20 21 For the most up-to-date information see the Parma Polyhedra Library 22 site: http://bugseng.com/products/ppl/ . */ 23 24 #ifndef PPL_math_utilities_defs_hh 25 #define PPL_math_utilities_defs_hh 1 26 27 #include "Coefficient_types.hh" 28 #include "Checked_Number_defs.hh" 29 #include <gmpxx.h> 30 31 namespace Parma_Polyhedra_Library { 32 33 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 34 //! Extract the numerator and denominator components of \p from. 35 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 36 template <typename T> 37 typename Enable_If<Is_Native_Or_Checked<T>::value, void>::type 38 numer_denom(const T& from, 39 Coefficient& numer, Coefficient& denom); 40 41 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 42 //! Divides \p x by \p y into \p to, rounding the result towards plus infinity. 43 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 44 template <typename T> 45 typename Enable_If<Is_Native_Or_Checked<T>::value, void>::type 46 div_round_up(T& to, 47 Coefficient_traits::const_reference x, 48 Coefficient_traits::const_reference y); 49 50 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 51 //! Assigns to \p x the minimum between \p x and \p y. 52 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 53 template <typename N> 54 void 55 min_assign(N& x, const N& y); 56 57 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 58 //! Assigns to \p x the maximum between \p x and \p y. 59 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 60 template <typename N> 61 void 62 max_assign(N& x, const N& y); 63 64 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 65 //! Returns <CODE>true</CODE> if and only if \p x is an even number. 66 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 67 template <typename T> 68 typename Enable_If<Is_Native_Or_Checked<T>::value, bool>::type 69 is_even(const T& x); 70 71 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 72 //! Returns <CODE>true</CODE> if and only if \f$x = -y\f$. 73 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 74 template <typename T> 75 typename Enable_If<Is_Native_Or_Checked<T>::value, bool>::type 76 is_additive_inverse(const T& x, const T& y); 77 78 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 79 /*! \brief 80 If \f$g\f$ is the GCD of \p x and \p y, the values of \p x and \p y 81 divided by \f$g\f$ are assigned to \p n_x and \p n_y, respectively. 82 83 \note 84 \p x and \p n_x may be the same object and likewise for 85 \p y and \p n_y. Any other aliasing results in undefined behavior. 86 */ 87 #endif 88 void 89 normalize2(Coefficient_traits::const_reference x, 90 Coefficient_traits::const_reference y, 91 Coefficient& n_x, Coefficient& n_y); 92 93 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 94 //! Returns <CODE>true</CODE> if and only if \p x is in canonical form. 95 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) 96 bool 97 is_canonical(const mpq_class& x); 98 99 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS 100 //! Returns a mask for the lowest \p n bits, 101 #endif 102 template <typename T> 103 T 104 low_bits_mask(unsigned n); 105 106 } // namespace Parma_Polyhedra_Library 107 108 #include "math_utilities_inlines.hh" 109 110 #endif // !defined(PPL_math_utilities_defs_hh) 111