/usr/include/fplll/nr/nr_Z_d.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 | /****************************
* Z=double specialization
****************************/
#ifndef FPLLL_NR_Z_D_H
#define FPLLL_NR_Z_D_H
FPLLL_BEGIN_NAMESPACE
/* specialization double as z */
#ifdef FPLLL_WITH_ZDOUBLE
template<>
inline Z_NR<double>::Z_NR() {}
template<>
inline Z_NR<double>::Z_NR(const Z_NR<double>& z) : data(z.data) {}
template<>
inline Z_NR<double>::~Z_NR() {}
/** get data */
template<>
inline double Z_NR<double>::get_d() const {
return data;
}
#ifdef FPLLL_WITH_LONG_DOUBLE
template<>
inline long double Z_NR<double>::get_ld() const {
return static_cast<long double>(data);
}
#endif
template<>
inline long Z_NR<double>::get_si() const {
return static_cast<long>(rint(data));
}
template<>
inline void Z_NR<double>::get_mpz(mpz_t r) const {
mpz_set_d (r, data);
}
template<>
inline long Z_NR<double>::exponent() const {
int int_expo;
frexp(data, &int_expo);
return static_cast<long>(int_expo);
}
/** set data */
template<>
inline void Z_NR<double>::set_str(const char* s) {
data = atof(s);
}
/** comparison */
template<>
inline int Z_NR<double>::cmp(const Z_NR<double>& m) const {
if (data > m.data) return 1;
if (data == m.data) return 0;
return -1;
}
template<>
inline int Z_NR<double>::sgn() const {
if (data > 0.0) return 1;
if (data == 0.0) return 0;
return -1;
}
/** operator */
template<>
inline void Z_NR<double>::operator=(const Z_NR<double>& a) {
data = a.data;
}
template<>
inline void Z_NR<double>::operator=(long a) {
data = static_cast<double>(a);
}
template<>
inline bool Z_NR<double>::operator<(const Z_NR<double>& a) const {
return data < a.data;
}
template<>
inline bool Z_NR<double>::operator<(long a) const {
return data < static_cast<double>(a);
}
template<>
inline bool Z_NR<double>::operator>(const Z_NR<double>& a) const {
return data > a.data;
}
template<>
inline bool Z_NR<double>::operator>(long a) const {
return data > static_cast<double>(a);
}
template<>
inline bool Z_NR<double>::operator<=(const Z_NR<double>& a) const {
return data <= a.data;
}
template<>
inline bool Z_NR<double>::operator<=(long a) const {
return data <= static_cast<double>(a);
}
template<>
inline bool Z_NR<double>::operator>=(const Z_NR<double>& a) const {
return data >= a.data;
}
template<>
inline bool Z_NR<double>::operator>=(long a) const {
return data >= static_cast<double>(a);
}
template<>
inline bool Z_NR<double>::operator==(const Z_NR<double>& a) const {
return data == a.data;
}
template<>
inline bool Z_NR<double>::operator==(long a) const {
return data == static_cast<double>(a);
}
template<>
inline bool Z_NR<double>::operator!=(const Z_NR<double>& a) const {
return data != a.data;
}
template<>
inline bool Z_NR<double>::operator!=(long a) const {
return data != static_cast<double>(a);
}
/** arithmetic */
template<>
inline void Z_NR<double>::add(const Z_NR<double>& a, const Z_NR<double>& b) {
data = a.data + b.data;
}
template<>
inline void Z_NR<double>::add_ui(const Z_NR<double>& a, unsigned int b) {
data = a.data + static_cast<double>(b);
}
template<>
inline void Z_NR<double>::sub(const Z_NR<double>& a, const Z_NR<double>& b) {
data = a.data - b.data;
}
template<>
inline void Z_NR<double>::sub_ui(const Z_NR<double>& a, unsigned int b) {
data = a.data - static_cast<double>(b);
}
template<>
inline void Z_NR<double>::neg(const Z_NR<double>& a) {
data = -a.data;
}
template<>
inline void Z_NR<double>::mul(const Z_NR<double>& a, const Z_NR<double>& b) {
data = a.data * b.data;
}
template<>
inline void Z_NR<double>::mul_si(const Z_NR<double>& a, long int b) {
data = a.data * static_cast<double>(b);
}
template<>
inline void Z_NR<double>::mul_ui(const Z_NR<double>& a, long unsigned int b) {
data = a.data * static_cast<double>(b);
}
template<>
inline void Z_NR<double>::mul_2si(const Z_NR<double>& a, long b) {
data = ldexp(a.data, b);
}
template<>
inline void Z_NR<double>::div_2si(const Z_NR<double>& a, long b) {
data = ldexp(a.data, -b);
}
template<>
inline void Z_NR<double>::addmul(const Z_NR<double>& a, const Z_NR<double>& b) {
data += a.data * b.data;
}
template<>
inline void Z_NR<double>::addmul_ui(const Z_NR<double>& a, unsigned long b) {
data += a.data * static_cast<double>(b);
}
template<>
inline void Z_NR<double>::addmul_si(const Z_NR<double>& a, long b) {
data += a.data * static_cast<double>(b);
}
template<>
inline void Z_NR<double>::submul(const Z_NR<double>& a, const Z_NR<double>& b) {
data -= a.data * b.data;
}
template<>
inline void Z_NR<double>::submul_ui(const Z_NR<double>& a, unsigned long b) {
data -= a.data * static_cast<double>(b);
}
template<>
inline void Z_NR<double>::abs(const Z_NR<double>& a) {
data = fabs(a.data);
}
template<>
inline void Z_NR<double>::swap(Z_NR<double>& a) {
std::swap(data, a.data);
}
/** random numbers */
template<>
inline void Z_NR<double>::randb(int bits) {
mpz_t temp;
mpz_init(temp);
mpz_urandomb(temp, RandGen::get_gmp_state(), bits);
data = mpz_get_d(temp);
mpz_clear(temp);
}
template<>
inline void Z_NR<double>::randb_si(int bits) {
randb (bits);
data = data * RandGenInt::get_bit();
}
template<>
inline void Z_NR<double>::randm(const Z_NR<double>& max) {
mpz_t temp, lim;
mpz_init(temp);
mpz_init(lim);
mpz_set_d(lim, max.data);
mpz_urandomm(temp, RandGen::get_gmp_state(), lim);
data = mpz_get_d(temp);
mpz_clear(temp);
mpz_clear(lim);
}
template<>
inline void Z_NR<double>::randm_si(const Z_NR<double>& max) {
randm (max);
data = data * RandGenInt::get_bit();
}
template<>
inline void Z_NR<double>::nextprime(const Z_NR<double>& nbr) {
mpz_t temp, temp2;
mpz_init(temp);
mpz_init(temp2);
mpz_set_d(temp, nbr.data);
mpz_nextprime(temp2, temp);
data = mpz_get_d(temp2);
mpz_clear(temp);
mpz_clear(temp2);
}
/* operator Z_NR<double> */
template<>
inline ostream& operator<<(ostream& os, const Z_NR<double>& x) {
return os << x.get_data();
}
template<>
inline istream& operator>>(istream& is, Z_NR<double>& x) {
return is >> x.get_data();
}
#endif // #ifdef FPLLL_WITH_ZDOUBLE
FPLLL_END_NAMESPACE
#endif
|