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>()
const;
186 #ifdef SOPLEX_WITH_GMP 632 #ifdef SOPLEX_WITH_GMP 647 mpq_init(privatevalue);
657 mpq_init(privatevalue);
666 mpq_init(privatevalue);
668 if(r == (
long double)(1.0))
670 else if(r == (
long double)(-1.0))
672 else if(r == (
long double)(0.0))
677 mpq_set_d(privatevalue,
double(r));
685 mpq_init(privatevalue);
696 mpq_set_d(privatevalue, r);
704 mpq_init(privatevalue);
715 mpq_set_si(privatevalue, i, 1);
723 mpq_init(privatevalue);
724 mpq_set(privatevalue, q);
729 #ifdef SOPLEX_WITH_BOOST 730 #ifdef SOPLEX_WITH_GMP 731 template <
typename T, boost::multiprecision::expression_
template_option eto>
732 Private(
const boost::multiprecision::number<T, eto>& q)
736 boost::multiprecision::mpq_rational tmp{q};
737 mpq_init(privatevalue);
738 mpq_set(privatevalue, tmp.backend().data());
746 mpq_clear(privatevalue);
752 #ifdef SOPLEX_PERFALT_4 768 if(r == (
long double)(0.0))
770 #ifdef SOPLEX_PERFALT_5a 771 #ifdef SOPLEX_PERFALT_1 773 if(mpq_sgn(privatevalue) != 0)
780 else if(r == (
long double)(1.0))
782 #ifdef SOPLEX_PERFALT_5b 788 else if(r == (
long double)(-1.0))
790 #ifdef SOPLEX_PERFALT_5b 797 mpq_set_d(this->privatevalue,
double(r));
808 #ifdef SOPLEX_PERFALT_5a 809 #ifdef SOPLEX_PERFALT_1 811 if(mpq_sgn(privatevalue) != 0)
820 #ifdef SOPLEX_PERFALT_5b 828 #ifdef SOPLEX_PERFALT_5b 835 mpq_set_d(privatevalue, r);
846 #ifdef SOPLEX_PERFALT_5a 847 #ifdef SOPLEX_PERFALT_1 849 if(mpq_sgn(privatevalue) != 0)
858 #ifdef SOPLEX_PERFALT_5b 866 #ifdef SOPLEX_PERFALT_5b 873 mpq_set_si(privatevalue, i, 1);
881 #ifdef SOPLEX_PERFALT_4 883 if(mpq_equal(this->privatevalue, q) != 0)
889 mpq_set(this->privatevalue, q);
893 #ifdef SOPLEX_WITH_BOOST 895 template <
typename T, boost::multiprecision::expression_
template_option eto>
900 boost::multiprecision::mpq_rational tmp{q};
901 mpq_set(this->privatevalue, tmp.backend().data());
930 #else // SOPLEX_WITH_GMP 939 long double privatevalue;
941 #ifdef SOPLEX_WITH_BOOST 942 template <
typename T, boost::multiprecision::expression_
template_option eto>
943 Private(
const boost::multiprecision::number<T, eto>& q)
945 privatevalue = (
long double)q;
948 template <
typename T, boost::multiprecision::expression_
template_option eto>
951 privatevalue = (
long double)q;
997 this->privatevalue = r;
1004 this->privatevalue = (
long double)(r);
1011 this->privatevalue = (
long double)(i);
1015 #endif // SOPLEX_WITH_GMP 1019 #ifdef SOPLEX_WITH_BOOST 1020 using namespace boost::multiprecision;
1026 template <
typename T, expression_
template_option eto>
1033 #ifndef SOPLEX_WITH_CPPMPF 1035 template <
typename T, expression_
template_option eto>
1036 Rational::operator number<T, eto>()
const 1044 #ifdef SOPLEX_WITH_GMP 1046 template<
unsigned bits, expression_
template_option eto>
1047 Rational::operator number<backends::cpp_dec_float<bits>, eto>()
const 1050 number<cpp_rational_backend, et_on> cpp_numb = cpp_rational(mpq_numb);
1051 return number<backends::cpp_dec_float<bits>, eto>(cpp_numb);
1055 template<
unsigned bits, expression_
template_option eto>
1056 Rational::operator number<backends::cpp_dec_float<bits>, eto>()
const 1066 #ifdef SOPLEX_WITH_MPFR 1067 template <
typename T, boost::multiprecision::expression_
template_option eto>
1101 #endif // SOPLEX_WITH_CPPMPF 1103 #ifdef SOPLEX_WITH_CPPMPF 1104 template <
typename T, boost::multiprecision::expression_
template_option eto>
1113 #endif // SOPLEX_WITH_CPPMPF 1139 #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