bernstein.cc: evalue2ex: represent fractional by scaled integer variable
[barvinok.git] / barvinok / NTL_QQ.h
blob73077d940b2ee7a48c581613295ecf9a7c2c85d7
1 #ifndef NTL_QQ_H
2 #define NTL_QQ_H
4 #include <NTL/ZZ.h>
5 #include <NTL/vector.h>
7 #ifdef NTL_STD_CXX
8 using namespace NTL;
9 #endif
11 struct QQ {
12 ZZ n;
13 ZZ d;
14 /* This is not thread-safe, but neither is NTL */
15 static ZZ tmp;
17 QQ() {}
18 QQ(int n, int d) {
19 this->n = n;
20 this->d = d;
23 QQ& canonicalize() {
24 GCD(tmp, n, d);
25 n /= tmp;
26 d /= tmp;
27 return *this;
30 QQ& operator += (const QQ& a) {
31 n *= a.d;
32 mul(tmp, d, a.n);
33 n += tmp;
34 d *= a.d;
35 return canonicalize();
38 QQ& operator *= (const QQ& a) {
39 n *= a.n;
40 d *= a.d;
41 return canonicalize();
44 QQ& operator *= (const ZZ& a) {
45 n *= a;
46 return *this;
50 NTL_vector_decl(QQ,vec_QQ);
52 vec_QQ& operator *= (vec_QQ& a, const ZZ& b);
53 vec_QQ& operator *= (vec_QQ& a, const QQ& b);
55 std::ostream& operator<< (std::ostream& os, const QQ& q);
56 std::istream& operator>> (std::istream& os, QQ& q);
58 NTL_io_vector_decl(QQ,vec_QQ);
60 #endif