1 /* Copyright (c) 1997-2021
2    Ewgenij Gawrilow, Michael Joswig, and the polymake team
3    Technische Universität Berlin, Germany
4    https://polymake.org
5 
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any
9    later version: http://www.gnu.org/licenses/gpl.txt.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 --------------------------------------------------------------------------------
16 */
17 
18 #if defined(__clang__)
19 #pragma clang diagnostic push
20 #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
21 #elif defined(__GNUC__)
22 #pragma GCC diagnostic push
23 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
24 #endif
25 
26 #include <gmpxx.h>
27 
28 #if defined(__clang__)
29 #pragma clang diagnostic pop
30 #elif defined(__GNUC__)
31 #pragma GCC diagnostic pop
32 #endif
33 
34 #include "polymake/Integer.h"
35 
36 namespace libnormaliz {
37 
try_convert(double & a,const pm::Integer & b)38 bool try_convert(double& a, const pm::Integer& b)
39 {
40    a = static_cast<double>(b);
41    return true;
42 }
43 
try_convert(long & a,const pm::Integer & b)44 bool try_convert(long& a, const pm::Integer& b)
45 {
46   if (b.fits_into_Int()) {
47     a = static_cast<long>(b);
48     return true;
49   }
50   return false;
51 }
52 
try_convert(long long & a,const pm::Integer & b)53 bool try_convert(long long& a, const pm::Integer& b)
54 {
55   if (b.fits_into_long_long()) {
56     a = static_cast<long long>(b);
57     return true;
58   }
59   return false;
60 }
61 
try_convert(mpz_class & a,const pm::Integer & b)62 bool try_convert(mpz_class& a, const pm::Integer& b)
63 {
64   a = mpz_class(b.get_rep());
65   return true;
66 }
67 
try_convert(pm::Integer & a,const mpz_class & b)68 bool try_convert(pm::Integer& a, const mpz_class& b)
69 {
70   a = pm::Integer(b);
71   return true;
72 }
73 
try_convert(pm::Integer & a,const long & b)74 bool try_convert(pm::Integer& a, const long& b)
75 {
76   a = b;
77   return true;
78 }
79 
try_convert(pm::Integer & a,const long long & b)80 bool try_convert(pm::Integer& a, const long long& b)
81 {
82   a = b;
83   return true;
84 }
85 
try_convert(pm::Integer & a,const double & b)86 bool try_convert(pm::Integer& a, const double& b)
87 {
88   a = b;
89   return true;
90 }
91 
convert_to_double(const pm::Integer & a)92 double convert_to_double(const pm::Integer& a)
93 {
94   return double(a);
95 }
96 
operator %(size_t a,const pm::Integer & b)97 pm::Integer operator%(size_t a, const pm::Integer& b)
98 {
99   if (a <= (unsigned long)std::numeric_limits<long>::max())
100     return long(a) % b;
101   else
102     return pm::Integer(a) % b;
103 }
104 
operator *(unsigned long a,const pm::Integer & b)105 pm::Integer operator*(unsigned long a, const pm::Integer& b)
106 {
107   if (a <= (unsigned long)std::numeric_limits<long>::max())
108     return long(a) * b;
109   else
110     return pm::Integer(a) * b;
111 }
112 
operator *(unsigned int a,const pm::Integer & b)113 pm::Integer operator*(unsigned int a, const pm::Integer& b)
114 {
115   return static_cast<unsigned long>(a) * b;
116 }
117 
int_quotient(pm::Integer & Quot,const pm::Integer & Num,const pm::Integer & Den)118 inline bool int_quotient(pm::Integer& Quot, const pm::Integer& Num, const pm::Integer& Den){
119    Quot = abs(Num)/abs(Den);
120    return Quot*abs(Den)!=abs(Num);
121 }
122 
int_quotient(long long & Quot,const pm::Integer & Num,const pm::Integer & Den)123 inline bool int_quotient(long long& Quot, const pm::Integer& Num, const pm::Integer& Den){
124    pm::Integer QI = abs(Num)/abs(Den);
125    Quot = (long long) QI;
126    return QI*abs(Den)!=abs(Num);
127 }
128 
129 }
130 
131 #if defined(__clang__)
132 #pragma clang diagnostic push
133 #pragma clang diagnostic ignored "-Wunused-variable"
134 #pragma clang diagnostic ignored "-Wshadow"
135 #pragma clang diagnostic ignored "-Wconversion"
136 #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
137 #pragma clang diagnostic ignored "-Wreturn-type"
138 #if __clang_major__ >= (defined(__APPLE__) ? 9 : 4)
139 #pragma clang diagnostic ignored "-Winstantiation-after-specialization"
140 #endif
141 #if defined(__APPLE__) && __clang_major__ >= 12
142 #pragma clang diagnostic ignored "-Wrange-loop-analysis"
143 #endif
144 #elif defined(__GNUC__)
145 #pragma GCC diagnostic push
146 #pragma GCC diagnostic ignored "-Wunused-variable"
147 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
148 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
149 #pragma GCC diagnostic ignored "-Wshadow"
150 #pragma GCC diagnostic ignored "-Wreturn-type"
151 #if __GNUC__ >= 6
152 #pragma GCC diagnostic ignored "-Wmisleading-indentation"
153 #if __GNUC__ >= 8
154 #pragma GCC diagnostic ignored "-Wcatch-value=0"
155 #endif // gcc8
156 #endif // gcc6
157 #pragma GCC diagnostic ignored "-Wconversion"
158 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
159 #endif
160 
161 #include "libnormaliz/linear_algebra.cpp"
162 #include "libnormaliz/cone_and_control.cpp"
163 #include "libnormaliz/enumeration.cpp"
164 #include "libnormaliz/other_algorithms.cpp"
165 #include "libnormaliz/nmz_nauty.cpp"
166 #include "libnormaliz/primal.cpp"
167 #include "libnormaliz/output.cpp"
168 
169 
170 #if defined(__clang__)
171 #pragma clang diagnostic pop
172 #elif defined(__GNUC__)
173 #pragma GCC diagnostic pop
174 #endif
175 
176 namespace libnormaliz {
177 
178 template<>
int_max_value_dual()179 pm::Integer int_max_value_dual<pm::Integer>()
180 {
181   assert(false);
182   return 0;
183 }
184 
185 template<>
int_max_value_primary()186 pm::Integer int_max_value_primary<pm::Integer>()
187 {
188   assert(false);
189   return 0;
190 }
191 
192 template<>
using_GMP()193 bool using_GMP<pm::Integer>()
194 {
195   return true;
196 }
197 
198 template<>
check_range(const pm::Integer & m)199 bool check_range<pm::Integer>(const pm::Integer& m)
200 {
201   return true;
202 }
203 
204 // avoid issue with libc++ and libgmpxx
205 template<>
ArithmeticException(const mpz_class & convert_number)206 ArithmeticException::ArithmeticException(const mpz_class& convert_number) {
207    std::stringstream stream;
208    stream << "Could not convert " << pm::Integer(convert_number) << ".\n";
209    stream << "Overflow detected. A fatal size excess or  a computation overflow.\n If Normaliz has terminated and you are "
210       "using LongLong, rerun without it.";
211    msg = stream.str();
212 }
213 
214 template class Cone<pm::Integer>;
215 template class Matrix<pm::Integer>;
216 template class Sublattice_Representation<pm::Integer>;
217 template class AutomorphismGroup<pm::Integer>;
218 }
219