From a30822cf64d7581afb1eb4da44f219e48088f19d Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 19 Jan 2007 17:35:38 +0100 Subject: [PATCH] QQ: add operator for multiplication by a scalar (ZZ) --- NTL_QQ.cc | 7 +++++++ barvinok/NTL_QQ.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/NTL_QQ.cc b/NTL_QQ.cc index 58c8164..ce5ae82 100644 --- a/NTL_QQ.cc +++ b/NTL_QQ.cc @@ -3,6 +3,13 @@ NTL_vector_impl(QQ,vec_QQ); +vec_QQ& operator *= (vec_QQ& a, const ZZ& b) +{ + for (int i = 0; i < a.length(); ++i) + a[i] *= b; + return a; +} + std::ostream& operator<< (std::ostream& os, const QQ& q) { os << q.n << "/" << q.d; diff --git a/barvinok/NTL_QQ.h b/barvinok/NTL_QQ.h index cb4be94..6c75bc3 100644 --- a/barvinok/NTL_QQ.h +++ b/barvinok/NTL_QQ.h @@ -17,6 +17,7 @@ struct QQ { this->n = n; this->d = d; } + QQ& operator += (const QQ& a) { ZZ g = GCD(d, a.d); ZZ num = a.n * (d / g) + (a.d / g) * n; @@ -32,10 +33,17 @@ struct QQ { d *= a.d; return *this; } + + QQ& operator *= (const ZZ& a) { + n *= a; + return *this; + } }; NTL_vector_decl(QQ,vec_QQ); +vec_QQ& operator *= (vec_QQ& a, const ZZ& b); + std::ostream& operator<< (std::ostream& os, const QQ& q); std::istream& operator>> (std::istream& os, QQ& q); -- 2.11.4.GIT