update isl to version 0.24
[barvinok.git] / barvinok / NTL_QQ.h
blob56ab1cfe28af3ffd10d67207629e132f20ca3765
1 #ifndef NTL_QQ_H
2 #define NTL_QQ_H
4 #include <barvinok/NTL.h>
6 using namespace NTL;
8 struct QQ {
9 ZZ n;
10 ZZ d;
11 /* This is not thread-safe, but neither is NTL */
12 static ZZ tmp;
14 QQ() {}
15 QQ(int n, int d) {
16 this->n = n;
17 this->d = d;
20 QQ& canonicalize() {
21 GCD(tmp, n, d);
22 n /= tmp;
23 d /= tmp;
24 return *this;
27 QQ& operator += (const QQ& a) {
28 n *= a.d;
29 mul(tmp, d, a.n);
30 n += tmp;
31 d *= a.d;
32 return canonicalize();
35 QQ& operator *= (const QQ& a) {
36 n *= a.n;
37 d *= a.d;
38 return canonicalize();
41 QQ& operator *= (const ZZ& a) {
42 n *= a;
43 return *this;
47 #ifdef NTL_vector_decl
48 NTL_vector_decl(QQ,vec_QQ);
49 #else
50 typedef Vec<QQ> vec_QQ;
51 #endif
53 vec_QQ& operator *= (vec_QQ& a, const ZZ& b);
54 vec_QQ& operator *= (vec_QQ& a, const QQ& b);
56 std::ostream& operator<< (std::ostream& os, const QQ& q);
57 std::istream& operator>> (std::istream& os, QQ& q);
59 #ifdef NTL_io_vector_decl
60 NTL_io_vector_decl(QQ,vec_QQ);
61 #endif
63 #endif