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