1 /* GMP_Integer class implementation: inline functions.
2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4
5 This file is part of the Parma Polyhedra Library (PPL).
6
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23
24 #ifndef PPL_GMP_Integer_inlines_hh
25 #define PPL_GMP_Integer_inlines_hh 1
26
27 #include "assertions.hh"
28
29 namespace Parma_Polyhedra_Library {
30
31 inline void
neg_assign(GMP_Integer & x)32 neg_assign(GMP_Integer& x) {
33 mpz_neg(x.get_mpz_t(), x.get_mpz_t());
34 }
35
36 inline void
neg_assign(GMP_Integer & x,const GMP_Integer & y)37 neg_assign(GMP_Integer& x, const GMP_Integer& y) {
38 mpz_neg(x.get_mpz_t(), y.get_mpz_t());
39 }
40
41 inline void
abs_assign(GMP_Integer & x)42 abs_assign(GMP_Integer& x) {
43 mpz_abs(x.get_mpz_t(), x.get_mpz_t());
44 }
45
46 inline void
abs_assign(GMP_Integer & x,const GMP_Integer & y)47 abs_assign(GMP_Integer& x, const GMP_Integer& y) {
48 mpz_abs(x.get_mpz_t(), y.get_mpz_t());
49 }
50
51 inline void
gcd_assign(GMP_Integer & x,const GMP_Integer & y,const GMP_Integer & z)52 gcd_assign(GMP_Integer& x, const GMP_Integer& y, const GMP_Integer& z) {
53 mpz_gcd(x.get_mpz_t(), y.get_mpz_t(), z.get_mpz_t());
54 }
55
56 inline void
rem_assign(GMP_Integer & x,const GMP_Integer & y,const GMP_Integer & z)57 rem_assign(GMP_Integer& x, const GMP_Integer& y, const GMP_Integer& z) {
58 mpz_tdiv_r(x.get_mpz_t(), y.get_mpz_t(), z.get_mpz_t());
59 }
60
61 inline void
gcdext_assign(GMP_Integer & x,GMP_Integer & s,GMP_Integer & t,const GMP_Integer & y,const GMP_Integer & z)62 gcdext_assign(GMP_Integer& x, GMP_Integer& s, GMP_Integer& t,
63 const GMP_Integer& y, const GMP_Integer& z) {
64 mpz_gcdext(x.get_mpz_t(),
65 s.get_mpz_t(), t.get_mpz_t(),
66 y.get_mpz_t(), z.get_mpz_t());
67 }
68
69 inline void
lcm_assign(GMP_Integer & x,const GMP_Integer & y,const GMP_Integer & z)70 lcm_assign(GMP_Integer& x, const GMP_Integer& y, const GMP_Integer& z) {
71 mpz_lcm(x.get_mpz_t(), y.get_mpz_t(), z.get_mpz_t());
72 }
73
74 inline void
add_mul_assign(GMP_Integer & x,const GMP_Integer & y,const GMP_Integer & z)75 add_mul_assign(GMP_Integer& x, const GMP_Integer& y, const GMP_Integer& z) {
76 mpz_addmul(x.get_mpz_t(), y.get_mpz_t(), z.get_mpz_t());
77 }
78
79 inline void
sub_mul_assign(GMP_Integer & x,const GMP_Integer & y,const GMP_Integer & z)80 sub_mul_assign(GMP_Integer& x, const GMP_Integer& y, const GMP_Integer& z) {
81 mpz_submul(x.get_mpz_t(), y.get_mpz_t(), z.get_mpz_t());
82 }
83
84 inline void
mul_2exp_assign(GMP_Integer & x,const GMP_Integer & y,unsigned int exp)85 mul_2exp_assign(GMP_Integer& x, const GMP_Integer& y, unsigned int exp) {
86 mpz_mul_2exp(x.get_mpz_t(), y.get_mpz_t(), exp);
87 }
88
89 inline void
div_2exp_assign(GMP_Integer & x,const GMP_Integer & y,unsigned int exp)90 div_2exp_assign(GMP_Integer& x, const GMP_Integer& y, unsigned int exp) {
91 mpz_tdiv_q_2exp(x.get_mpz_t(), y.get_mpz_t(), exp);
92 }
93
94 inline void
exact_div_assign(GMP_Integer & x,const GMP_Integer & y,const GMP_Integer & z)95 exact_div_assign(GMP_Integer& x, const GMP_Integer& y, const GMP_Integer& z) {
96 PPL_ASSERT(y % z == 0);
97 mpz_divexact(x.get_mpz_t(), y.get_mpz_t(), z.get_mpz_t());
98 }
99
100 inline void
sqrt_assign(GMP_Integer & x,const GMP_Integer & y)101 sqrt_assign(GMP_Integer& x, const GMP_Integer& y) {
102 mpz_sqrt(x.get_mpz_t(), y.get_mpz_t());
103 }
104
105 inline int
cmp(const GMP_Integer & x,const GMP_Integer & y)106 cmp(const GMP_Integer& x, const GMP_Integer& y) {
107 return mpz_cmp(x.get_mpz_t(), y.get_mpz_t());
108 }
109
110 inline const mpz_class&
raw_value(const GMP_Integer & x)111 raw_value(const GMP_Integer& x) {
112 return x;
113 }
114
115 inline mpz_class&
raw_value(GMP_Integer & x)116 raw_value(GMP_Integer& x) {
117 return x;
118 }
119
120 } // namespace Parma_Polyhedra_Library
121
122 #endif // !defined(PPL_GMP_Integer_inlines_hh)
123