1 /** @file ring_traits.h
3 * Functions for polynomial ring arithmetic. */
6 * GiNaC Copyright (C) 1999-2022 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef GINAC_RING_TRAITS_H
24 #define GINAC_RING_TRAITS_H
26 #include <cln/integer.h>
27 #include <cln/modinteger.h>
31 static inline cln::cl_I div(const cln::cl_I& x, const cln::cl_I& y)
33 return cln::exquo(x, y);
36 /// Exact integer division.
37 /// Check if y divides x, if yes put the quotient into q, otherwise don't
38 /// touch q. Returns true if y divides x and false if not.
39 static inline bool div(cln::cl_I& q, const cln::cl_I& x, const cln::cl_I& y)
41 const cln::cl_I_div_t qr = cln::truncate2(x, y);
42 if (zerop(qr.remainder)) {
49 static inline cln::cl_I get_ring_elt(const cln::cl_I& sample, const int val)
51 return cln::cl_I(val);
54 static inline cln::cl_MI get_ring_elt(const cln::cl_MI& sample, const int val)
56 return sample.ring()->canonhom(val);
60 static inline T the_one(const T& sample)
62 return get_ring_elt(sample, 1);
67 #endif // GINAC_RING_TRAITS_H