/usr/include/fplll/nr/nr_Z_mpz.inl is in libfplll-dev 5.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | /****************************
* Z=mpz_t specialization
****************************/
#ifndef FPLLL_NR_Z_MPZ_H
#define FPLLL_NR_Z_MPZ_H
FPLLL_BEGIN_NAMESPACE
/* specialization */
template<>
inline Z_NR<mpz_t>::Z_NR() {
mpz_init(data);
}
template<>
inline Z_NR<mpz_t>::Z_NR(const Z_NR<mpz_t>& z) {
mpz_init_set(data, z.data);
}
template<>
inline Z_NR<mpz_t>::~Z_NR() {
mpz_clear(data);
}
/** get data */
template<>
inline double Z_NR<mpz_t>::get_d() const {
return mpz_get_d(data);
}
#ifdef FPLLL_WITH_LONG_DOUBLE
template<>
inline long double Z_NR<mpz_t>::get_ld() const {
return LDConvHelper::mpz_get_ld(data);
}
#endif
template<>
inline long Z_NR<mpz_t>::get_si() const {
return mpz_get_si(data);
}
template<>
inline void Z_NR<mpz_t>::get_mpz(mpz_t r) const {
mpz_set (r, data);
}
template<>
inline long Z_NR<mpz_t>::exponent() const {
long expo;
mpz_get_d_2exp(&expo, data);
return expo;
}
/** set data */
template<>
inline void Z_NR<mpz_t>::set_str(const char* s) {
mpz_set_str(data, s, 10);
}
/** comparison */
template<>
inline int Z_NR<mpz_t>::cmp(const Z_NR<mpz_t>& m) const {
int c = mpz_cmp(data, m.data);
if (c > 0) return 1;
if (c == 0) return 0;
return -1;
}
template<>
inline int Z_NR<mpz_t>::sgn() const {
return mpz_sgn(data);
}
/** operator */
template<>
inline void Z_NR<mpz_t>::operator=(const Z_NR<mpz_t>& a) {
mpz_set(data, a.data);
}
template<>
inline void Z_NR<mpz_t>::operator=(const mpz_t& a) {
mpz_set(data, a);
}
template<>
inline void Z_NR<mpz_t>::operator=(long a) {
mpz_set_si(data, a);
}
template<>
inline bool Z_NR<mpz_t>::operator<(const Z_NR<mpz_t>& a) const {
return mpz_cmp(data, a.data) < 0;
}
template<>
inline bool Z_NR<mpz_t>::operator<(long a) const {
return mpz_cmp_si(data, a) < 0;
}
template<>
inline bool Z_NR<mpz_t>::operator>(const Z_NR<mpz_t>& a) const {
return mpz_cmp(data, a.data) > 0;
}
template<>
inline bool Z_NR<mpz_t>::operator>(long a) const {
return mpz_cmp_si(data, a) > 0;
}
template<>
inline bool Z_NR<mpz_t>::operator<=(const Z_NR<mpz_t>& a) const {
return mpz_cmp(data, a.data) <= 0;
}
template<>
inline bool Z_NR<mpz_t>::operator<=(long a) const {
return mpz_cmp_si(data, a) <= 0;
}
template<>
inline bool Z_NR<mpz_t>::operator>=(const Z_NR<mpz_t>& a) const {
return mpz_cmp(data, a.data) >= 0;
}
template<>
inline bool Z_NR<mpz_t>::operator>=(long a) const {
return mpz_cmp_si(data, a) >= 0;
}
template<>
inline bool Z_NR<mpz_t>::operator==(const Z_NR<mpz_t>& a) const {
return mpz_cmp(data, a.data) == 0;
}
template<>
inline bool Z_NR<mpz_t>::operator==(long a) const {
return mpz_cmp_si(data, a) == 0;
}
template<>
inline bool Z_NR<mpz_t>::operator!=(const Z_NR<mpz_t>& a) const {
return mpz_cmp(data, a.data) != 0;
}
template<>
inline bool Z_NR<mpz_t>::operator!=(long a) const {
return mpz_cmp_si(data, a) != 0;
}
/** arithmetic */
template<>
inline void Z_NR<mpz_t>::add(const Z_NR<mpz_t>& a, const Z_NR<mpz_t>& b) {
mpz_add(data, a.data, b.data);
}
template<>
inline void Z_NR<mpz_t>::add_ui(const Z_NR<mpz_t>& a, unsigned int b) {
mpz_add_ui(data, a.data, b);
}
template<>
inline void Z_NR<mpz_t>::sub(const Z_NR<mpz_t>& a, const Z_NR<mpz_t>& b) {
mpz_sub(data, a.data, b.data);
}
template<>
inline void Z_NR<mpz_t>::sub_ui(const Z_NR<mpz_t>& a, unsigned int b) {
mpz_sub_ui(data, a.data, b);
}
template<>
inline void Z_NR<mpz_t>::neg(const Z_NR<mpz_t>& a) {
mpz_neg(data, a.data);
}
template<>
inline void Z_NR<mpz_t>::mul(const Z_NR<mpz_t>& a, const Z_NR<mpz_t>& b) {
mpz_mul(data, a.data, b.data);
}
template<>
inline void Z_NR<mpz_t>::mul_si(const Z_NR<mpz_t>& a, long b) {
mpz_mul_si(data, a.data, b);
}
template<>
inline void Z_NR<mpz_t>::mul_ui(const Z_NR<mpz_t>& a, unsigned long b) {
mpz_mul_ui(data, a.data, b);
}
template<>
inline void Z_NR<mpz_t>::mul_2si(const Z_NR<mpz_t>& a, long b) {
if (b >= 0)
mpz_mul_2exp(data, a.data, b);
else
mpz_div_2exp(data, a.data, -b);
}
template<>
inline void Z_NR<mpz_t>::div_2si(const Z_NR<mpz_t>& a, long b) {
if (b >= 0)
mpz_div_2exp(data, a.data, b);
else
mpz_mul_2exp(data, a.data, -b);
}
template<>
inline void Z_NR<mpz_t>::addmul(const Z_NR<mpz_t>& a, const Z_NR<mpz_t>& b) {
mpz_addmul(data, a.data, b.data);
}
template<>
inline void Z_NR<mpz_t>::addmul_ui(const Z_NR<mpz_t>& a, unsigned long b) {
mpz_addmul_ui(data, a.data, b);
}
template<>
inline void Z_NR<mpz_t>::addmul_si(const Z_NR<mpz_t>& a, long b) {
if (b >= 0)
mpz_addmul_ui(data, a.data, static_cast<unsigned long>(b));
else
mpz_submul_ui(data, a.data, static_cast<unsigned long>(-b));
}
template<>
inline void Z_NR<mpz_t>::submul(const Z_NR<mpz_t>& a, const Z_NR<mpz_t>& b) {
mpz_submul(data, a.data, b.data);
}
template<>
inline void Z_NR<mpz_t>::submul_ui(const Z_NR<mpz_t>& a,unsigned long b) {
mpz_submul_ui(data, a.data, b);
}
template<>
inline void Z_NR<mpz_t>::abs(const Z_NR<mpz_t>& x) {
mpz_abs(data,x.data);
}
template<>
inline void Z_NR<mpz_t>::swap(Z_NR<mpz_t>& a) {
mpz_swap(data, a.data);
}
/** random numbers */
template<>
inline void Z_NR<mpz_t>::randb(int bits) {
mpz_urandomb(data, RandGen::get_gmp_state(), bits);
if (bits > 32){
unsigned long int tmp = mpz_get_ui(data);
gmp_randseed_ui(RandGen::gmp_state, tmp*tmp);
}
}
template<>
inline void Z_NR<mpz_t>::randb_si(int bits) {
randb(bits);
if (RandGenInt::get_bit() < 0)
mpz_neg(data, data);
}
template<>
inline void Z_NR<mpz_t>::randm(const Z_NR<mpz_t>& max) {
mpz_urandomm(data, RandGen::get_gmp_state(), max.data);
}
template<>
inline void Z_NR<mpz_t>::randm_si(const Z_NR<mpz_t>& max) {
randm(max);
if (RandGenInt::get_bit() < 0)
mpz_neg(data, data);
}
template<>
inline void Z_NR<mpz_t>::nextprime(const Z_NR<mpz_t>& nbr) {
mpz_nextprime(data, nbr.data);
}
/* operators Z_NR<mpz_t> */
template<>
inline ostream& operator<<(ostream& os, const Z_NR<mpz_t>& x) {
int size = mpz_sizeinbase(x.get_data(), 10) + 2;
char* s = new char[size];
mpz_get_str(s, 10, x.get_data());
os << s;
delete [] s;
return os;
}
template<>
inline istream& operator>>(istream& is, Z_NR<mpz_t>& x) {
static string s;
char c;
s.clear();
if (!(is >> c)) return is;
if (c == '-') {
s += c;
if (!(is >> c)) return is;
}
if (!(c >= '0' && c <= '9')) {
is.setstate(ios::failbit);
return is;
}
do {
s += c;
} while (is.get(c) && c >= '0' && c <= '9');
if (is.fail()) return is;
if (is.eof())
is.clear();
else
is.putback(c);
if (mpz_set_str(x.get_data(), s.c_str(), 10)) {
is.setstate(ios::failbit);
}
return is;
}
FPLLL_END_NAMESPACE
#endif
|