32 #ifdef SOPLEX_WITH_BOOST 33 #include "boost/multiprecision/number.hpp" 35 #ifdef SOPLEX_WITH_MPFR 36 #include "boost/multiprecision/mpfr.hpp" 39 #ifdef SOPLEX_WITH_CPPMPF 40 #include "boost/multiprecision/cpp_dec_float.hpp" 41 #include "boost/multiprecision/cpp_int.hpp" 45 #ifdef SOPLEX_WITH_GMP 47 #ifdef SOPLEX_WITH_BOOST 48 #include "boost/multiprecision/gmp.hpp" 68 #ifdef SOPLEX_WITH_GMP 75 Rational(
const int& i,
const bool& dummy);
107 #ifdef SOPLEX_WITH_GMP 112 #ifdef SOPLEX_WITH_BOOST 114 template <
typename T, boost::multiprecision::expression_
template_option eto>
115 Rational(
const boost::multiprecision::number<T, eto>& q);
147 #ifdef SOPLEX_WITH_GMP 158 #ifdef SOPLEX_WITH_BOOST 163 template <
typename T, boost::multiprecision::expression_
template_option eto>
171 operator double()
const;
172 operator long double()
const;
173 operator float()
const;
174 #ifdef SOPLEX_WITH_BOOST 175 #ifndef SOPLEX_WITH_CPPMPF 177 template <
typename T, boost::multiprecision::expression_
template_option eto>
178 operator boost::multiprecision::number<T, eto>()
const;
181 template <
unsigned bits, boost::multiprecision::expression_
template_option eto>
182 operator boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<bits>, eto>()
187 #ifdef SOPLEX_WITH_GMP 633 #ifdef SOPLEX_WITH_GMP 648 mpq_init(privatevalue);
658 mpq_init(privatevalue);
667 mpq_init(privatevalue);
669 if(r == (
long double)(1.0))
671 else if(r == (
long double)(-1.0))
673 else if(r == (
long double)(0.0))
678 mpq_set_d(privatevalue,
double(r));
686 mpq_init(privatevalue);
697 mpq_set_d(privatevalue, r);
705 mpq_init(privatevalue);
716 mpq_set_si(privatevalue, i, 1);
724 mpq_init(privatevalue);
725 mpq_set(privatevalue, q);
730 #ifdef SOPLEX_WITH_BOOST 731 #ifdef SOPLEX_WITH_GMP 732 template <
typename T, boost::multiprecision::expression_
template_option eto>
733 Private(
const boost::multiprecision::number<T, eto>& q)
737 boost::multiprecision::mpq_rational tmp{q};
738 mpq_init(privatevalue);
739 mpq_set(privatevalue, tmp.backend().data());
747 mpq_clear(privatevalue);
753 #ifdef SOPLEX_PERFALT_4 769 if(r == (
long double)(0.0))
771 #ifdef SOPLEX_PERFALT_5a 772 #ifdef SOPLEX_PERFALT_1 774 if(mpq_sgn(privatevalue) != 0)
781 else if(r == (
long double)(1.0))
783 #ifdef SOPLEX_PERFALT_5b 789 else if(r == (
long double)(-1.0))
791 #ifdef SOPLEX_PERFALT_5b 798 mpq_set_d(this->privatevalue,
double(r));
809 #ifdef SOPLEX_PERFALT_5a 810 #ifdef SOPLEX_PERFALT_1 812 if(mpq_sgn(privatevalue) != 0)
821 #ifdef SOPLEX_PERFALT_5b 829 #ifdef SOPLEX_PERFALT_5b 836 mpq_set_d(privatevalue, r);
847 #ifdef SOPLEX_PERFALT_5a 848 #ifdef SOPLEX_PERFALT_1 850 if(mpq_sgn(privatevalue) != 0)
859 #ifdef SOPLEX_PERFALT_5b 867 #ifdef SOPLEX_PERFALT_5b 874 mpq_set_si(privatevalue, i, 1);
882 #ifdef SOPLEX_PERFALT_4 884 if(mpq_equal(this->privatevalue, q) != 0)
890 mpq_set(this->privatevalue, q);
894 #ifdef SOPLEX_WITH_BOOST 896 template <
typename T, boost::multiprecision::expression_
template_option eto>
901 boost::multiprecision::mpq_rational tmp{q};
902 mpq_set(this->privatevalue, tmp.backend().data());
931 #else // SOPLEX_WITH_GMP 940 long double privatevalue;
942 #ifdef SOPLEX_WITH_BOOST 943 template <
typename T, boost::multiprecision::expression_
template_option eto>
944 Private(
const boost::multiprecision::number<T, eto>& q)
946 privatevalue = (
long double)q;
949 template <
typename T, boost::multiprecision::expression_
template_option eto>
952 privatevalue = (
long double)q;
998 this->privatevalue = r;
1005 this->privatevalue = (
long double)(r);
1012 this->privatevalue = (
long double)(i);
1016 #endif // SOPLEX_WITH_GMP 1020 #ifdef SOPLEX_WITH_BOOST 1021 using namespace boost::multiprecision;
1027 template <
typename T, expression_
template_option eto>
1034 #ifndef SOPLEX_WITH_CPPMPF 1036 template <
typename T, expression_
template_option eto>
1037 Rational::operator number<T, eto>()
const 1045 #ifdef SOPLEX_WITH_GMP 1047 template<
unsigned bits, expression_
template_option eto>
1048 Rational::operator number<backends::cpp_dec_float<bits>, eto>()
const 1051 number<cpp_rational_backend, et_on> cpp_numb = cpp_rational(mpq_numb);
1052 return number<backends::cpp_dec_float<bits>, eto>(cpp_numb);
1056 template<
unsigned bits, expression_
template_option eto>
1057 Rational::operator number<backends::cpp_dec_float<bits>, eto>()
const 1067 #ifdef SOPLEX_WITH_MPFR 1068 template <
typename T, boost::multiprecision::expression_
template_option eto>
1102 #endif // SOPLEX_WITH_CPPMPF 1104 #ifdef SOPLEX_WITH_CPPMPF 1105 template <
typename T, boost::multiprecision::expression_
template_option eto>
1114 #endif // SOPLEX_WITH_CPPMPF 1140 #endif // _RATIONAL_H_ Rational & addProduct(const Rational &r, const Rational &s)
add product of two rationals
bool isAdjacentTo(const double &d) const
checks if d is exactly equal to the Rational and if not, if it is one of the two adjacent doubles ...
bool isNextTo(const double &d)
checks if d is the closest number that can be represented by double
Generic Real linked list.
friend Rational spxAbs(const Rational &r)
Absolute.
Memory allocation routines.
friend std::string rationalToString(const Rational &r, const int precision)
convert rational number to string
int dlcmSizeRational(const Rational *vector, const int length, const int base)
Size of least common multiple of denominators in rational vector.
static const Rational ZERO
rational zero (GMP only)
Generic Real linked list.Class IdList implements an intrusive Real linked list as a template class...
friend bool operator<(const Rational &r, const Rational &s)
less than operator
static THREADLOCAL bool useListMem
list of unused Private objects; note that this cannot be used if SOPLEX_WITH_GMP is not defined...
Private & operator=(const int &i)
assignment operator from int
Rational operator*(const Rational &r) const
multiplication operator
Private *const & prev() const
previous Private element
int sizeInBase(const int base=2) const
Size in specified base (bit size for base 2)
friend bool operator<=(const Rational &r, const Rational &s)
less than or equal to operator
Rational operator-(const Rational &r) const
subtraction operator
friend bool operator!=(const Rational &r, const Rational &s)
inequality operator
Rational & subProduct(const Rational &r, const Rational &s)
subtract product of two rationals
Rational & invert()
inversion
friend bool operator>=(const Rational &r, const Rational &s)
greater than or equal to operator
Private *& prev()
previous Private element
int totalSizeRational(const Rational *vector, const int length, const int base)
Total size of rational vector.
Wrapper for GMP type mpq_class.We wrap mpq_class so that we can replace it by a double type if GMP is...
static void disableListMem()
disables list memory
Private *& next()
next Private element
Private & operator=(const long double &r)
assignment operator from long double
static const Rational NEGONE
rational minus one (GMP only)
Private & operator=(const double &r)
assignment operator from double
Rational spxLdexp(Rational x, int exp)
Rational & operator/=(const Rational &r)
division assignment operator
Rational & operator-=(const Rational &r)
subtraction assignment operator
void spx_alloc(T &p, int n=1)
Allocate memory.
static void freeListMem()
frees the unused rational elements in the memory list
int dmaxSizeRational(const Rational *vector, const int length, const int base)
Size of largest denominator in rational vector.
Private * theprev
pointer to the previous element in the list
Private()
default constructor
Rational & operator*=(const Rational &r)
multiplication assignment operator operator
Private & operator=(const Private &p)
assignment operator
Private(const double &r)
constructor from double
bool readString(const char *s)
read Rational from string
static int precision()
returns precision of Rational implementation, i.e., number of bits used to store Rational numbers (IN...
friend int sign(const Rational &r)
Sign function; returns 1 if r > 0, 0 if r = 0, and -1 if r < 0.
Defines the "Pimpl"-class Private.
friend std::ostream & operator<<(std::ostream &os, const Rational &q)
print Rational
mpq_t privatevalue
actual value of the Rational object
Private(const int &i)
constructor from int
static void enableListMem()
enables list memory
const mpq_t & getMpqRef() const
provides read-only access to underlying mpq_t
Private(const long double &r)
constructor from long double
static const Rational POSONE
rational plus one (GMP only)
Debugging, floating point type and parameter definitions.
friend bool operator==(const Rational &r, const Rational &s)
equality operator
Rational spxFrexp(Rational r, int *d)
friend int compareRational(const Rational &r, const Rational &s)
comparison operator returning a positive value if r > s, zero if r = s, and a negative value if r < s...
Rational operator+(const Rational &r) const
addition operator
Everything should be within this namespace.
Private * thenext
pointer to the next element in the list
~Private()
constructor from boost number
const mpq_t * getMpqPtr() const
provides read-only access to underlying mpq_t
Rational operator/(const Rational &r) const
division operator
friend bool readStringRational(const char *s, Rational &value)
read Rational from string
Rational & operator=(const Rational &)
assignment operator
static THREADLOCAL IdList< Private > unusedPrivateList
list of unused Private objects
Rational & subQuotient(const Rational &r, const Rational &s)
subtract quotient of two rationals, r divided by s
friend bool operator>(const Rational &r, const Rational &s)
greater than operator
mpq_t * getMpqPtr_w() const
provides write access to underlying mpq_t; use with care
Private & operator=(const mpq_t &q)
assignment operator from mpq_t
Private(const Private &p)
copy constructor
Private(const mpq_t &q)
constructor from mpq_t (GMP only)
Rational()
default constructor
Private *const & next() const
next Private element
mpq_t & getMpqRef_w() const
provides write access to underlying mpq_t; use with care
#define THREADLOCAL
SOPLEX_DEBUG.
Rational & addQuotient(const Rational &r, const Rational &s)
add quotient of two rationals, r divided by s
Rational & operator+=(const Rational &r)
addition assignment operator
Rational & powRound()
round up to next power of two