update pet for support for recent clangs
[barvinok.git] / barvinok / NTL_QQ.h
blobce0cf60da4bd7bdbf02b8b959f596bf9ffd3c392
1 #ifndef NTL_QQ_H
2 #define NTL_QQ_H
4 #include <barvinok/NTL.h>
6 #ifdef NTL_STD_CXX
7 using namespace NTL;
8 #endif
10 struct QQ {
11 ZZ n;
12 ZZ d;
13 /* This is not thread-safe, but neither is NTL */
14 static ZZ tmp;
16 QQ() {}
17 QQ(int n, int d) {
18 this->n = n;
19 this->d = d;
22 QQ& canonicalize() {
23 GCD(tmp, n, d);
24 n /= tmp;
25 d /= tmp;
26 return *this;
29 QQ& operator += (const QQ& a) {
30 n *= a.d;
31 mul(tmp, d, a.n);
32 n += tmp;
33 d *= a.d;
34 return canonicalize();
37 QQ& operator *= (const QQ& a) {
38 n *= a.n;
39 d *= a.d;
40 return canonicalize();
43 QQ& operator *= (const ZZ& a) {
44 n *= a;
45 return *this;
49 NTL_vector_decl(QQ,vec_QQ);
51 vec_QQ& operator *= (vec_QQ& a, const ZZ& b);
52 vec_QQ& operator *= (vec_QQ& a, const QQ& b);
54 std::ostream& operator<< (std::ostream& os, const QQ& q);
55 std::istream& operator>> (std::istream& os, QQ& q);
57 NTL_io_vector_decl(QQ,vec_QQ);
59 #endif