SoPlex Documentation
Loading...
Searching...
No Matches
rational.h
Go to the documentation of this file.
1
2/* ----------------------------------------------------------------------
3 * This file is autogenerated from the file multiprecision.hpp.in during
4 * the cmake configuration of your project. If you need to make changes
5 * edit the original file.
6 * ----------------------------------------------------------------------
7 */
8#ifndef __SOPLEX_MULTIPRECISION_HPP_
9#define __SOPLEX_MULTIPRECISION_HPP_
10#include <numeric>
11#include <vector>
12#include <string>
13#include "soplex/spxdefines.h"
14
15#ifdef SOPLEX_WITH_GMP
16#include <gmp.h>
17#endif
18
19#ifdef SOPLEX_WITH_BOOST
20#include <boost/multiprecision/number.hpp>
21
22#ifdef SOPLEX_WITH_GMP
23#include <boost/multiprecision/gmp.hpp>
24
25namespace soplex
26{
27
28using namespace boost::multiprecision;
29using Rational = number<gmp_rational, et_off>;
30using Integer = number<gmp_int, et_off>;
31inline void SpxLcm(Integer& result, Integer a, Integer b)
32{
33 mpz_lcm(result.backend().data(), a.backend().data(), b.backend().data());
34}
35inline void SpxGcd(Integer& result, Integer a, Integer b)
36{
37 mpz_gcd(result.backend().data(), a.backend().data(), b.backend().data());
38}
39
40} // namespace soplex
41#else
42#include <boost/multiprecision/cpp_int.hpp>
43#include <boost/multiprecision/detail/default_ops.hpp>
44
45namespace soplex
46{
47
48using namespace boost::multiprecision;
49using Rational = cpp_rational;
50using Integer = cpp_int;
51inline void SpxLcm(Integer& result, Integer a, Integer b)
52{
53 result = boost::multiprecision::lcm(a, b);
54}
55inline void SpxGcd(Integer& result, Integer a, Integer b)
56{
57 result = boost::multiprecision::gcd(a, b);
58}
59
60} // namespace soplex
61#endif
62
63namespace soplex
64{
65
66inline void printRational(Rational r)
67{
68 std::cout << r << std::endl;
69}
70
71inline void printInteger(Integer r)
72{
73 std::cout << r << std::endl;
74}
75inline bool isAdjacentTo(const Rational& r, const double& d)
76{
77 double x = (double) r;
78 double a;
79 double b;
80 Rational tmp = x;
81
82 // the rational value is representable in double precision
83 if(tmp == r)
84 return true;
85 // the rounded value is smaller than the rational value
86 else if(tmp < r)
87 {
88 a = x;
89 b = (double)nextafter(a, 1e100);
90 }
91 // the rounded value is larger than the rational value
92 else
93 {
94 b = x;
95 a = (double)nextafter(b, -1e100);
96 }
97
98 return ((a == d) || (b == d));
99}
100
101inline void invert(Rational& r)
102{
103 r = Rational(denominator(r), numerator(r));
104}
105
106/// round up to next power of two
107inline void powRound(Rational& r)
108{
109 Integer roundval;
110 Integer den;
111 Integer num;
112
113 num = numerator(r);
114 den = denominator(r);
115 roundval = num / den;
116
117 size_t binlog = roundval == 0 ? 1 : msb(roundval) + 1;
118 Integer base = 2;
119
120 roundval = boost::multiprecision::pow(base, (unsigned int)binlog);
121
122 r = roundval;
123}
124
125/// returns the order of magnitude of the given rational
126inline int orderOfMagnitude(Rational& r)
127{
128 if(numerator(r) == 0 || (int) log10((double)numerator(r)) == log10((double)denominator(r)))
129 return 0;
130 else
131 return (int) log10((double)numerator(r)) - (int) log10((double)denominator(r));
132}
133
134/* find substring, ignore case */
135static
136std::string::const_iterator findSubStringIC(const std::string& substr, const std::string& str)
137{
138 auto it = std::search(
139 str.begin(), str.end(),
140 substr.begin(), substr.end(),
141 [](char ch1, char ch2)
142 {
143 return std::toupper(ch1) == std::toupper(ch2);
144 }
145 );
146 return it;
147}
148
149inline Rational ratFromString(const char* desc)
150{
151 Rational res;
152
153 if(0 == strcmp(desc, "inf"))
154 {
155 res = 1e100;
156 }
157 else if(0 == strcmp(desc, "-inf"))
158 {
159 res = -1e100;
160 }
161 else
162 {
163 std::string s(desc);
164
165 /* case 1: string is given in nom/den format */
166 if(s.find_first_of(".Ee") == std::string::npos)
167 {
168 if(s[0] == '+')
169 res = Rational(desc + 1);
170 else
171 res = Rational(desc);
172 }
173 /* case 2: string is given as base-10 decimal number */
174 else
175 {
176 std::string::const_iterator it = findSubStringIC("e", s);
177 int mult = 0;
178
179 if(it != s.end())
180 {
181 int exponentidx = int(it - s.begin());
182 mult = std::stoi(s.substr(exponentidx + 1, s.length()));
183 s = s.substr(0, exponentidx);
184 }
185
186 // std::cout << s << std::endl;
187 if(s[0] == '.')
188 s.insert(0, "0");
189
190 size_t pos = s.find('.');
191
192 // if s contains a ., convert it to a rational
193 if(pos != std::string::npos)
194 {
195 size_t exp = s.length() - 1 - pos;
196 std::string den("1");
197
198 for(size_t i = 0; i < exp; ++i)
199 den.append("0");
200
201 s.erase(pos, 1);
202 assert(std::all_of(s.begin() + 1, s.end(), ::isdigit));
203
204 // remove padding 0s
205 if(s[0] == '-')
206 s.erase(1, SOPLEX_MIN(s.substr(1).find_first_not_of('0'), s.size() - 1));
207 else
208 s.erase(0, SOPLEX_MIN(s.find_first_not_of('0'), s.size() - 1));
209
210 s.append("/");
211 s.append(den);
212 }
213
214 if(s[0] == '+')
215 res = Rational(s.substr(1));
216 else
217 res = Rational(s);
218
219 res *= pow(10, mult);
220 }
221 }
222
223 return res;
224}
225
226} // namespace soplex
227#else
228
229#ifndef SOPLEX_WITH_GMP
230using mpq_t = char;
231#endif
232
233using Integer = int;
234// this is a placeholder class to ensure compilation when boost ist not linked. Rationals need BOOST in order to function.
235// coverity[missing_move_assign]
237{
238
239public:
240
241 ///@name Construction and destruction
242 ///@{
243
244 inline void rationalErrorMessage() const
245 {
246 SPX_MSG_ERROR(std::cerr << "Using rational methods without linking boost is not supported" <<
247 std::endl;)
248 };
249
250 /// default constructor
251 inline Rational()
252 {
253 };
254 /// copy constructor
255 inline Rational(const Rational& r)
256 {
257 };
258 /// constructor from long double
259 inline Rational(const long double& r)
260 {
261 };
262 /// constructor from double
263 inline Rational(const double& r)
264 {
265 };
266 ///constructor from int
267 inline Rational(const int& i)
268 {
269 };
270 /// constructor from Integer
271 inline Rational(const Integer& num, const Integer& den)
272 {
273 };
274 /// constructor from mpq_t (GMP only)
275 inline Rational(const mpq_t& q)
276 {
277 };
278#ifdef SOPLEX_WITH_BOOST
279 // constructor from boost number
280 inline template <typename T, boost::multiprecision::expression_template_option eto>
281 Rational(const boost::multiprecision::number<T, eto>& q)
282 {
283 };
284#endif
285 /// destructor
286 inline ~Rational()
287 {
288 };
289
290 /// assignment operator
292 {
293 return *this;
294 };
295 /// assignment operator from long double
296 inline Rational& operator=(const long double& r)
297 {
298 return *this;
299 };
300 /// assignment operator from double
301 inline Rational& operator=(const double& r)
302 {
303 return *this;
304 };
305 /// assignment operator from int
306 inline Rational& operator=(const int& i)
307 {
308 return *this;
309 };
310 /// assignment operator from mpq_t
311 inline Rational& operator=(const mpq_t& q)
312 {
313 return *this;
314 };
315
316 inline void assign(const Rational&)
317 {
319 };
320 inline void assign(const long double& r)
321 {
323 };
324 inline void assign(const double& r)
325 {
327 };
328 inline void assign(const int& i)
329 {
331 };
332
333 ///@name Typecasts
334 ///@{
335
336 inline operator double() const
337 {
338 return 0;
339 };
340 inline operator long double() const
341 {
342 return 0;
343 };
344 inline operator float() const
345 {
346 return 0;
347 };
348#ifdef SOPLEX_WITH_BOOST
349#ifndef SOPLEX_WITH_CPPMPF
350 // Operator to typecast Rational to one of the Boost Number types
351 inline template <typename T, boost::multiprecision::expression_template_option eto>
352 operator boost::multiprecision::number<T, eto>() const
353 {
355 return 0;
356 };
357#else
358 // Operator to typecast Rational to one of the Boost Number types
359 inline template <unsigned bits, boost::multiprecision::expression_template_option eto>
360 operator boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<bits>, eto>()
361 const
362 {
364 return 0;
365 };
366#endif
367#endif
368
369 ///@name Typecasts
370 ///@{
371
372 ///@}
373
374
375 ///@name Arithmetic operators
376 ///@{
377
378 /// addition operator
379 inline Rational operator+(const Rational& r) const
380 {
382 return *this;
383 }
384 /// addition assignment operator
385 inline Rational operator+=(const Rational& r)
386 {
388 return *this;
389 }
390 /// addition operator for doubles
391 inline Rational operator+(const double& r) const
392 {
394 return *this;
395 }
396 /// addition assignment operator for doubles
397 inline Rational operator+=(const double& r)
398 {
400 return *this;
401 }
402 /// addition operator for ints
403 inline Rational operator+(const int& r) const
404 {
406 return *this;
407 }
408 /// addition assignment operator for ints
409 inline Rational operator+=(const int& r)
410 {
412 return *this;
413 }
414 /// subtraction operator
415 inline Rational operator-(const Rational& r) const
416 {
418 return *this;
419 }
420 /// subtraction assignment operator
421 inline Rational operator-=(const Rational& r)
422 {
424 return *this;
425 }
426 /// subtraction operator for doubles
427 inline Rational operator-(const double& r) const
428 {
430 return *this;
431 }
432 /// subtraction assignment operator for doubles
433 inline Rational operator-=(const double& r)
434 {
436 return *this;
437 }
438 /// subtraction operator for ints
439 inline Rational operator-(const int& r) const
440 {
442 return *this;
443 }
444 /// subtraction assignment operator for ints
445 inline Rational operator-=(const int& r)
446 {
448 return *this;
449 }
450 /// multiplication operator
451 inline Rational operator*(const Rational& r) const
452 {
454 return *this;
455 }
456 /// multiplication assignment operator operator
457 inline Rational operator*=(const Rational& r)
458 {
460 return *this;
461 }
462 /// multiplication operator for doubles
463 inline Rational operator*(const double& r) const
464 {
466 return *this;
467 }
468 /// multiplication assignment operator for doubles
469 inline Rational operator*=(const double& r)
470 {
472 return *this;
473 }
474 /// multiplication operator for ints
475 inline Rational operator*(const int& r) const
476 {
478 return *this;
479 }
480 /// multiplication assignment operator for ints
481 inline Rational operator*=(const int& r)
482 {
484 return *this;
485 }
486 /// division operator
487 inline Rational operator/(const Rational& r) const
488 {
490 return *this;
491 }
492 /// division assignment operator
493 inline Rational operator/=(const Rational& r)
494 {
496 return *this;
497 }
498 /// division operator for doubles
499 inline Rational operator/(const double& r) const
500 {
502 return *this;
503 }
504 /// division assignment operator for doubles
505 inline Rational operator/=(const double& r)
506 {
508 return *this;
509 }
510 /// division operator for ints
511 inline Rational operator/(const int& r) const
512 {
514 return *this;
515 }
516 /// division assignment operator for ints
517 inline Rational operator/=(const int& r)
518 {
520 return *this;
521 }
522 /// add product of two rationals
524 {
526 return *this;
527 }
528
529 /// subtract product of two rationals
531 {
533 return *this;
534 }
535
536 /// add quotient of two rationals, r divided by s
538 {
540 return *this;
541 }
542
543 /// subtract quotient of two rationals, r divided by s
545 {
547 return *this;
548 }
549
550 ///@}
551
552
553 ///@name Methods for checking exactness of doubles
554 ///@{
555
556 /// checks if \p d is exactly equal to the Rational and if not, if it is one of the two adjacent doubles
557 inline bool isAdjacentTo(const double& d) const
558 {
560 return false;
561 };
562
563 ///@}
564
565
566 ///@name Methods for querying size
567 ///@{
568
569 /// Size in specified base (bit size for base 2)
570 int sizeInBase(const int base = 2) const
571 {
573 return 0;
574 };
575
576 ///@}
577
578
579 ///@name Conversion from and to String
580 ///@{
581 inline friend std::ostream& operator<<(std::ostream& os, const Rational& r)
582 {
584 return os;
585 };
586 inline std::string str() const
587 {
588 this->rationalErrorMessage();
589 return std::string("");
590 };
591 ///@}
592
593 ///@name Friends
594 ///@{
595
596 inline friend int compareRational(const Rational& r, const Rational& s)
597 {
599 return 0;
600 };
601 inline friend bool operator!=(const Rational& r, const Rational& s)
602 {
604 return false;
605 };
606 inline friend bool operator==(const Rational& r, const Rational& s)
607 {
609 return false;
610 };
611 inline friend bool operator<(const Rational& r, const Rational& s)
612 {
614 return false;
615 };
616 inline friend bool operator<=(const Rational& r, const Rational& s)
617 {
619 return false;
620 };
621 inline friend bool operator>(const Rational& r, const Rational& s)
622 {
624 return false;
625 };
626 inline friend bool operator>=(const Rational& r, const Rational& s)
627 {
629 return false;
630 };
631
632 inline friend bool operator!=(const Rational& r, const double& s)
633 {
635 return false;
636 };
637 inline friend bool operator==(const Rational& r, const double& s)
638 {
640 return false;
641 };
642 inline friend bool operator<(const Rational& r, const double& s)
643 {
645 return false;
646 };
647 inline friend bool operator<=(const Rational& r, const double& s)
648 {
650 return false;
651 };
652 inline friend bool operator>(const Rational& r, const double& s)
653 {
655 return false;
656 };
657 inline friend bool operator>=(const Rational& r, const double& s)
658 {
660 return false;
661 };
662
663 inline friend bool operator!=(const double& r, const Rational& s)
664 {
666 return false;
667 };
668 inline friend bool operator==(const double& r, const Rational& s)
669 {
671 return false;
672 };
673 inline friend bool operator<(const double& r, const Rational& s)
674 {
676 return false;
677 };
678 inline friend bool operator<=(const double& r, const Rational& s)
679 {
681 return false;
682 };
683 inline friend bool operator>(const double& r, const Rational& s)
684 {
686 return false;
687 };
688 inline friend bool operator>=(const double& r, const Rational& s)
689 {
691 return false;
692 };
693
694 inline friend bool operator!=(const Rational& r, const long double& s)
695 {
697 return false;
698 };
699 inline friend bool operator==(const Rational& r, const long double& s)
700 {
702 return false;
703 };
704 inline friend bool operator<(const Rational& r, const long double& s)
705 {
707 return false;
708 };
709 inline friend bool operator<=(const Rational& r, const long double& s)
710 {
712 return false;
713 };
714 inline friend bool operator>(const Rational& r, const long double& s)
715 {
717 return false;
718 };
719 inline friend bool operator>=(const Rational& r, const long double& s)
720 {
722 return false;
723 };
724
725 inline friend bool operator!=(const long double& r, const Rational& s)
726 {
728 return false;
729 };
730 inline friend bool operator==(const long double& r, const Rational& s)
731 {
733 return false;
734 };
735 inline friend bool operator<(const long double& r, const Rational& s)
736 {
738 return false;
739 };
740 inline friend bool operator<=(const long double& r, const Rational& s)
741 {
743 return false;
744 };
745 inline friend bool operator>(const long double& r, const Rational& s)
746 {
748 return false;
749 };
750 inline friend bool operator>=(const long double& r, const Rational& s)
751 {
753 return false;
754 };
755
756 inline friend bool operator!=(const Rational& r, const float& s)
757 {
759 return false;
760 };
761 inline friend bool operator==(const Rational& r, const float& s)
762 {
764 return false;
765 };
766 inline friend bool operator<(const Rational& r, const float& s)
767 {
769 return false;
770 };
771 inline friend bool operator<=(const Rational& r, const float& s)
772 {
774 return false;
775 };
776 inline friend bool operator>(const Rational& r, const float& s)
777 {
779 return false;
780 };
781 inline friend bool operator>=(const Rational& r, const float& s)
782 {
784 return false;
785 };
786
787 inline friend bool operator!=(const float& r, const Rational& s)
788 {
790 return false;
791 };
792 inline friend bool operator==(const float& r, const Rational& s)
793 {
795 return false;
796 };
797 inline friend bool operator<(const float& r, const Rational& s)
798 {
800 return false;
801 };
802 inline friend bool operator<=(const float& r, const Rational& s)
803 {
805 return false;
806 };
807 inline friend bool operator>(const float& r, const Rational& s)
808 {
810 return false;
811 };
812 inline friend bool operator>=(const float& r, const Rational& s)
813 {
815 return false;
816 };
817
818 inline friend Rational operator+(const double& d, const Rational& r)
819 {
821 return r;
822 };
823 inline friend Rational operator-(const double& d, const Rational& r)
824 {
826 return r;
827 };
828 inline friend Rational operator*(const double& d, const Rational& r)
829 {
831 return r;
832 };
833 inline friend Rational operator/(const double& d, const Rational& r)
834 {
836 return r;
837 };
838
839 inline friend bool operator!=(const Rational& r, const int& s)
840 {
842 return false;
843 };
844 inline friend bool operator==(const Rational& r, const int& s)
845 {
847 return false;
848 };
849 inline friend bool operator<(const Rational& r, const int& s)
850 {
852 return false;
853 };
854 inline friend bool operator<=(const Rational& r, const int& s)
855 {
857 return false;
858 };
859 inline friend bool operator>(const Rational& r, const int& s)
860 {
862 return false;
863 };
864 inline friend bool operator>=(const Rational& r, const int& s)
865 {
867 return false;
868 };
869
870 inline friend bool operator!=(const int& r, const Rational& s)
871 {
873 return false;
874 };
875 inline friend bool operator==(const int& r, const Rational& s)
876 {
878 return false;
879 };
880 inline friend bool operator<(const int& r, const Rational& s)
881 {
883 return false;
884 };
885 inline friend bool operator<=(const int& r, const Rational& s)
886 {
888 return false;
889 };
890 inline friend bool operator>(const int& r, const Rational& s)
891 {
893 return false;
894 };
895 inline friend bool operator>=(const int& r, const Rational& s)
896 {
898 return false;
899 };
900
901 inline friend Rational operator+(const int& d, const Rational& r)
902 {
904 return r;
905 };
906 inline friend Rational operator-(const int& d, const Rational& r)
907 {
909 return r;
910 };
911 inline friend Rational operator*(const int& d, const Rational& r)
912 {
914 return r;
915 };
916 inline friend Rational operator/(const int& d, const Rational& r)
917 {
919 return r;
920 };
921
922 inline friend Rational spxAbs(const Rational& r)
923 {
925 return r;
926 };
927 inline friend int sign(const Rational& r)
928 {
930 return 0;
931 };
932 inline friend Rational operator-(const Rational& q)
933 {
935 return q;
936 };///@name Construction and destruction
937 ///@{
938};
939
940inline Integer numerator(const Rational& r)
941{
943 return 0;
944}
946{
948 return 0;
949}
950inline Rational ratFromString(const char* desc)
951{
952 return Rational();
953}
955{
957 return 0;
958}
959inline void SpxLcm(Integer& result, Integer a, Integer b) {}
960inline void SpxGcd(Integer& result, Integer a, Integer b) {}
961inline void divide_qr(Integer& result, Integer& result2, Integer a, Integer b) {}
962inline void invert(Rational& r)
963{
965}
966inline void powRound(Rational& r)
967{
969}
970#endif
971
972namespace soplex
973{
974
975/// Size in specified base (bit size for base 2)
976inline int sizeInBase(const Rational R, const int base)
977{
978#ifndef SOPLEX_WITH_BOOST
979 SPX_MSG_ERROR(std::cerr << "ERROR: rational solve without Boost not defined!" << std::endl;)
980 return 0;
981#else
982
983 if(R == Rational(0))
984 return 3;
985
986 Integer num = numerator(R);
987 Integer den = denominator(R);
988 size_t numsize, densize;
989
990#ifdef SOPLEX_WITH_GMP
991 densize = mpz_sizeinbase(den.backend().data(), base);
992 numsize = mpz_sizeinbase(num.backend().data(), base);
993#else
994
995 if(base != 2)
996 {
997 densize = (size_t)(log2(den.convert_to<double>()) / log2(double(base))) + 1;
998 numsize = (size_t)(log2(num.convert_to<double>()) / log2(double(base))) + 1;
999 }
1000 else
1001 {
1002 densize = msb(den) + 1;
1003 numsize = msb(num) + 1;
1004 }
1005
1006#endif
1007
1008 return (int)(densize + numsize);
1009#endif
1010}
1011/// Total size of rational vector.
1012inline int totalSizeRational(const Rational* vector, const int length, const int base)
1013{
1014 assert(vector != nullptr);
1015 assert(length >= 0);
1016 assert(base >= 0);
1017
1018 int size = 0;
1019
1020 for(int i = 0; i < length; i++)
1021 size += sizeInBase(vector[i], base);
1022
1023 return size;
1024}
1025
1026/// Size of least common multiple of denominators in rational vector.
1027inline int dlcmSizeRational(const Rational* vector, const int length, const int base)
1028{
1029 assert(vector != nullptr);
1030 assert(length >= 0);
1031
1032#ifndef SOPLEX_WITH_BOOST
1033 SPX_MSG_ERROR(std::cerr << "ERROR: rational solve without Boost not defined!" << std::endl;)
1034 return 0;
1035#else
1036
1037 Integer lcm = 1;
1038
1039 for(int i = 0; i < length; i++)
1040 SpxLcm(lcm, lcm, denominator(vector[i]));
1041
1042 int size = sizeInBase(Rational(lcm), base) + 1;
1043
1044 return size;
1045#endif
1046}
1047
1048/// Size of largest denominator in rational vector.
1049inline int dmaxSizeRational(const Rational* vector, const int length, const int base)
1050{
1051 assert(vector != nullptr);
1052 assert(length >= 0);
1053#ifndef SOPLEX_WITH_BOOST
1054 SPX_MSG_ERROR(std::cerr << "ERROR: rational solve without Boost not defined!" << std::endl;)
1055 return 0;
1056#else
1057
1058 size_t dmax = 0;
1059
1060 for(int i = 0; i < length; i++)
1061 {
1062 size_t dsize = sizeInBase(Rational(denominator(vector[i])), base) + 1;
1063
1064 if(dsize > dmax)
1065 dmax = dsize;
1066 }
1067
1068 return (int)dmax;
1069#endif
1070}
1071
1072} // namespace soplex
1073#endif
1074//}
friend bool operator<=(const long double &r, const Rational &s)
Definition rational.h:740
friend bool operator!=(const Rational &r, const float &s)
Definition rational.h:756
Rational operator*=(const Rational &r)
multiplication assignment operator operator
Definition rational.h:457
friend Rational operator/(const double &d, const Rational &r)
Definition rational.h:833
friend int sign(const Rational &r)
Definition rational.h:927
friend Rational operator*(const int &d, const Rational &r)
Definition rational.h:911
Rational operator/(const Rational &r) const
division operator
Definition rational.h:487
Rational operator-=(const int &r)
subtraction assignment operator for ints
Definition rational.h:445
friend bool operator!=(const int &r, const Rational &s)
Definition rational.h:870
friend bool operator<=(const Rational &r, const float &s)
Definition rational.h:771
void assign(const int &i)
Definition rational.h:328
Rational(const Rational &r)
copy constructor
Definition rational.h:255
int sizeInBase(const int base=2) const
Size in specified base (bit size for base 2)
Definition rational.h:570
Rational & addProduct(const Rational &r, const Rational &s)
add product of two rationals
Definition rational.h:523
friend bool operator==(const Rational &r, const Rational &s)
Definition rational.h:606
friend bool operator>=(const long double &r, const Rational &s)
Definition rational.h:750
Rational(const Integer &num, const Integer &den)
constructor from Integer
Definition rational.h:271
Rational(const long double &r)
constructor from long double
Definition rational.h:259
friend bool operator<=(const float &r, const Rational &s)
Definition rational.h:802
friend bool operator>=(const float &r, const Rational &s)
Definition rational.h:812
Rational operator*(const int &r) const
multiplication operator for ints
Definition rational.h:475
friend bool operator>=(const double &r, const Rational &s)
Definition rational.h:688
friend bool operator<(const Rational &r, const long double &s)
Definition rational.h:704
friend bool operator>=(const Rational &r, const long double &s)
Definition rational.h:719
friend bool operator<=(const Rational &r, const int &s)
Definition rational.h:854
Rational operator/=(const double &r)
division assignment operator for doubles
Definition rational.h:505
friend bool operator<(const Rational &r, const Rational &s)
Definition rational.h:611
friend bool operator<(const double &r, const Rational &s)
Definition rational.h:673
friend bool operator==(const double &r, const Rational &s)
Definition rational.h:668
friend bool operator>(const Rational &r, const long double &s)
Definition rational.h:714
Rational & operator=(const mpq_t &q)
assignment operator from mpq_t
Definition rational.h:311
void assign(const long double &r)
Definition rational.h:320
friend bool operator!=(const Rational &r, const int &s)
Definition rational.h:839
~Rational()
destructor
Definition rational.h:286
Rational & operator=(const double &r)
assignment operator from double
Definition rational.h:301
friend bool operator<(const float &r, const Rational &s)
Definition rational.h:797
Rational operator-(const Rational &r) const
subtraction operator
Definition rational.h:415
friend Rational operator+(const double &d, const Rational &r)
Definition rational.h:818
friend bool operator<=(const double &r, const Rational &s)
Definition rational.h:678
Rational operator+=(const Rational &r)
addition assignment operator
Definition rational.h:385
friend bool operator>(const double &r, const Rational &s)
Definition rational.h:683
Rational(const mpq_t &q)
constructor from mpq_t (GMP only)
Definition rational.h:275
void assign(const Rational &)
Definition rational.h:316
Rational & subProduct(const Rational &r, const Rational &s)
subtract product of two rationals
Definition rational.h:530
Rational operator*=(const int &r)
multiplication assignment operator for ints
Definition rational.h:481
friend int compareRational(const Rational &r, const Rational &s)
Definition rational.h:596
Rational & subQuotient(const Rational &r, const Rational &s)
subtract quotient of two rationals, r divided by s
Definition rational.h:544
friend bool operator==(const long double &r, const Rational &s)
Definition rational.h:730
friend bool operator<(const Rational &r, const float &s)
Definition rational.h:766
Rational operator-(const int &r) const
subtraction operator for ints
Definition rational.h:439
friend bool operator>(const long double &r, const Rational &s)
Definition rational.h:745
friend bool operator<(const int &r, const Rational &s)
Definition rational.h:880
friend bool operator!=(const long double &r, const Rational &s)
Definition rational.h:725
friend bool operator!=(const Rational &r, const long double &s)
Definition rational.h:694
Rational operator+(const double &r) const
addition operator for doubles
Definition rational.h:391
friend std::ostream & operator<<(std::ostream &os, const Rational &r)
Definition rational.h:581
friend bool operator>=(const Rational &r, const int &s)
Definition rational.h:864
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
Definition rational.h:557
friend Rational operator-(const int &d, const Rational &r)
Definition rational.h:906
friend bool operator>=(const int &r, const Rational &s)
Definition rational.h:895
Rational & operator=(const Rational &)
assignment operator
Definition rational.h:291
friend bool operator<=(const int &r, const Rational &s)
Definition rational.h:885
friend bool operator<=(const Rational &r, const double &s)
Definition rational.h:647
friend bool operator!=(const double &r, const Rational &s)
Definition rational.h:663
friend bool operator>=(const Rational &r, const double &s)
Definition rational.h:657
Rational operator/(const int &r) const
division operator for ints
Definition rational.h:511
Rational(const int &i)
constructor from int
Definition rational.h:267
Rational operator-=(const double &r)
subtraction assignment operator for doubles
Definition rational.h:433
friend bool operator>(const int &r, const Rational &s)
Definition rational.h:890
Rational(const double &r)
constructor from double
Definition rational.h:263
friend bool operator>(const float &r, const Rational &s)
Definition rational.h:807
friend bool operator==(const Rational &r, const float &s)
Definition rational.h:761
friend Rational operator*(const double &d, const Rational &r)
Definition rational.h:828
Rational operator-=(const Rational &r)
subtraction assignment operator
Definition rational.h:421
friend bool operator<=(const Rational &r, const long double &s)
Definition rational.h:709
friend bool operator!=(const Rational &r, const Rational &s)
Definition rational.h:601
Rational operator+=(const int &r)
addition assignment operator for ints
Definition rational.h:409
Rational & operator=(const int &i)
assignment operator from int
Definition rational.h:306
Rational operator+=(const double &r)
addition assignment operator for doubles
Definition rational.h:397
friend bool operator!=(const float &r, const Rational &s)
Definition rational.h:787
Rational operator*(const Rational &r) const
multiplication operator
Definition rational.h:451
friend bool operator>=(const Rational &r, const Rational &s)
Definition rational.h:626
friend Rational spxAbs(const Rational &r)
Definition rational.h:922
friend bool operator==(const float &r, const Rational &s)
Definition rational.h:792
Rational operator/=(const int &r)
division assignment operator for ints
Definition rational.h:517
friend bool operator==(const int &r, const Rational &s)
Definition rational.h:875
Rational operator*=(const double &r)
multiplication assignment operator for doubles
Definition rational.h:469
friend bool operator>(const Rational &r, const Rational &s)
Definition rational.h:621
friend bool operator>(const Rational &r, const float &s)
Definition rational.h:776
friend bool operator!=(const Rational &r, const double &s)
Definition rational.h:632
friend bool operator<(const long double &r, const Rational &s)
Definition rational.h:735
friend bool operator<=(const Rational &r, const Rational &s)
Definition rational.h:616
friend bool operator>=(const Rational &r, const float &s)
Definition rational.h:781
friend bool operator==(const Rational &r, const double &s)
Definition rational.h:637
Rational & operator=(const long double &r)
assignment operator from long double
Definition rational.h:296
friend bool operator<(const Rational &r, const double &s)
Definition rational.h:642
friend bool operator==(const Rational &r, const long double &s)
Definition rational.h:699
friend bool operator>(const Rational &r, const double &s)
Definition rational.h:652
Rational operator/(const double &r) const
division operator for doubles
Definition rational.h:499
void assign(const double &r)
Definition rational.h:324
friend bool operator==(const Rational &r, const int &s)
Definition rational.h:844
friend Rational operator/(const int &d, const Rational &r)
Definition rational.h:916
Rational operator+(const Rational &r) const
addition operator
Definition rational.h:379
Rational operator-(const double &r) const
subtraction operator for doubles
Definition rational.h:427
Rational()
default constructor
Definition rational.h:251
Rational operator*(const double &r) const
multiplication operator for doubles
Definition rational.h:463
Rational operator+(const int &r) const
addition operator for ints
Definition rational.h:403
friend Rational operator-(const double &d, const Rational &r)
Definition rational.h:823
friend bool operator>(const Rational &r, const int &s)
Definition rational.h:859
friend Rational operator-(const Rational &q)
Definition rational.h:932
std::string str() const
Definition rational.h:586
void rationalErrorMessage() const
Definition rational.h:244
Rational & addQuotient(const Rational &r, const Rational &s)
add quotient of two rationals, r divided by s
Definition rational.h:537
friend bool operator<(const Rational &r, const int &s)
Definition rational.h:849
friend Rational operator+(const int &d, const Rational &r)
Definition rational.h:901
Rational operator/=(const Rational &r)
division assignment operator
Definition rational.h:493
Everything should be within this namespace.
int dmaxSizeRational(const Rational *vector, const int length, const int base)
Size of largest denominator in rational vector.
Definition rational.h:1049
int dlcmSizeRational(const Rational *vector, const int length, const int base)
Size of least common multiple of denominators in rational vector.
Definition rational.h:1027
int sizeInBase(const Rational R, const int base)
Size in specified base (bit size for base 2)
Definition rational.h:976
int totalSizeRational(const Rational *vector, const int length, const int base)
Total size of rational vector.
Definition rational.h:1012
int orderOfMagnitude(Rational &r)
Definition rational.h:954
int Integer
Definition rational.h:233
void powRound(Rational &r)
Definition rational.h:966
void divide_qr(Integer &result, Integer &result2, Integer a, Integer b)
Definition rational.h:961
void invert(Rational &r)
Definition rational.h:962
Integer numerator(const Rational &r)
Definition rational.h:940
void SpxLcm(Integer &result, Integer a, Integer b)
Definition rational.h:959
void SpxGcd(Integer &result, Integer a, Integer b)
Definition rational.h:960
Integer denominator(const Rational &r)
Definition rational.h:945
Rational ratFromString(const char *desc)
Definition rational.h:950
Debugging, floating point type and parameter definitions.
#define SPX_MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition spxdefines.h:163
#define SOPLEX_MIN(x, y)
Definition spxdefines.h:298