]> www.ginac.de Git - ginac.git/blob - ginac/polynomial/ring_traits.hpp
polynomial: introduce a helper function to divide polynomial by ring element.
[ginac.git] / ginac / polynomial / ring_traits.hpp
1 #ifndef GINAC_RING_TRAITS_HPP
2 #define GINAC_RING_TRAITS_HPP
3 #include <cln/integer.h>
4 #include <cln/modinteger.h>
5
6 namespace cln
7 {
8 static inline cln::cl_I div(const cln::cl_I& x, const cln::cl_I& y)
9 {
10         return cln::exquo(x, y);
11 }
12
13 /// Exact integer division.
14 /// Check if y divides x, if yes put the quotient into q, otherwise don't
15 /// touch q. Returns true if y divides x and false if not.
16 static inline bool div(cln::cl_I& q, const cln::cl_I& x, const cln::cl_I& y)
17 {
18         const cln::cl_I_div_t qr = cln::truncate2(x, y);
19         if (zerop(qr.remainder)) {
20                 q = qr.quotient;
21                 return true;
22         }
23         return false;
24 }
25
26 static inline cln::cl_I get_ring_elt(const cln::cl_I& sample, const int val)
27 {
28         return cln::cl_I(val);
29 }
30
31 static inline cln::cl_MI get_ring_elt(const cln::cl_MI& sample, const int val)
32 {
33         return sample.ring()->canonhom(val);
34 }
35
36 template<typename T>
37 static inline T the_one(const T& sample)
38 {
39         return get_ring_elt(sample, 1);
40 }
41
42 } // namespace cln
43
44 #endif // GINAC_RING_TRAITS_HPP
45