X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fpolynomial%2Fring_traits.hpp;h=540a6bd716e455eb7a084528b0d681ee3c8a08e9;hp=10fb172a5550be0626415879e8f0e423c0d4f7b4;hb=47b7f9c9b4a5bd91c7c83b12bac8481b55bf4b92;hpb=55fcb39a1209898ec43694f7e25ffb4572b0c4d1 diff --git a/ginac/polynomial/ring_traits.hpp b/ginac/polynomial/ring_traits.hpp index 10fb172a..540a6bd7 100644 --- a/ginac/polynomial/ring_traits.hpp +++ b/ginac/polynomial/ring_traits.hpp @@ -10,6 +10,19 @@ static inline cln::cl_I div(const cln::cl_I& x, const cln::cl_I& y) return cln::exquo(x, y); } +/// Exact integer division. +/// Check if y divides x, if yes put the quotient into q, otherwise don't +/// touch q. Returns true if y divides x and false if not. +static inline bool div(cln::cl_I& q, const cln::cl_I& x, const cln::cl_I& y) +{ + const cln::cl_I_div_t qr = cln::truncate2(x, y); + if (zerop(qr.remainder)) { + q = qr.quotient; + return true; + } + return false; +} + static inline cln::cl_I get_ring_elt(const cln::cl_I& sample, const int val) { return cln::cl_I(val);