23 #ifndef PLLL_INCLUDE_GUARD__NINT_WRAPPER
24 #define PLLL_INCLUDE_GUARD__NINT_WRAPPER
46 template<
typename Type>
81 enum { is_cputype =
true, is_realtype =
false, is_inttype =
true, is_exact =
true,
82 is_modulo =
true, has_infinity =
false, has_uniform_rng =
true };
174 template<
typename Type>
184 is_cpp_string =
false,
187 has_uniform_rng =
true,
191 has_infinity =
false,
192 is_variable_precision =
false,
193 has_squareroot =
false,
194 has_full_power =
false,
195 has_special_fns =
false,
196 has_huge_exponent =
false,
197 has_constants =
false,
198 has_trigonometric =
false
216 template<
typename Type>
224 template<
typename Type>
232 template<
typename Type>
233 inline bool operator <= (const NInt<Type> & a,
const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
240 template<
typename Type>
248 template<
typename Type>
249 inline bool operator < (const NInt<Type> & a,
const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
256 template<
typename Type>
268 template<
typename Type>
277 template<
typename Type>
286 template<
typename Type>
295 template<
typename Type>
304 template<
typename Type>
313 template<
typename Type>
325 template<
typename Type>
326 inline NInt<Type> operator << (const NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
338 template<
typename Type>
350 template<
typename Type>
351 inline NInt<Type> operator << (const NInt<Type> & a,
const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
363 template<
typename Type>
371 template<
typename Type>
379 template<typename Type>
380 inline
NInt<Type> operator -- (
NInt<Type> & cur,
int) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
387 template<typename Type>
388 inline
NInt<Type> & operator ++ (
NInt<Type> & cur) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
395 template<typename Type>
396 inline
NInt<Type> & operator -- (
NInt<Type> & cur) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
409 template<typename Type>
410 inline
NInt<Type> & operator -= (
NInt<Type> & cur, const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
418 template<typename Type>
419 inline
NInt<Type> & operator += (
NInt<Type> & cur, const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
427 template<typename Type>
428 inline
NInt<Type> & operator *= (
NInt<Type> & cur, const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
436 template<typename Type>
437 inline
NInt<Type> & operator /= (
NInt<Type> & cur, const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
446 template<typename Type>
447 inline
NInt<Type> & operator %= (
NInt<Type> & cur, const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
458 template<typename Type>
459 inline
NInt<Type> & operator <<= (
NInt<Type> & cur,
long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
470 template<typename Type>
471 inline
NInt<Type> & operator >>= (
NInt<Type> & cur,
long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
482 template<typename Type>
483 inline
NInt<Type> & operator <<= (
NInt<Type> & cur, const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
494 template<typename Type>
495 inline
NInt<Type> & operator >>= (
NInt<Type> & cur, const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
507 template<typename Type>
508 inline
bool isZero(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
516 template<typename Type>
517 inline
bool isOne(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
525 template<typename Type>
526 inline
bool isPMOne(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
534 template<typename Type>
535 inline
bool isPMTwo(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
543 template<typename Type>
544 inline
bool isPositive(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
552 template<typename Type>
553 inline
bool isNonNegative(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
561 template<typename Type>
562 inline
bool isNegative(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
570 template<typename Type>
571 inline
bool isNonPositive(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
584 template<typename Type>
585 inline
void add(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
593 template<typename Type>
594 inline
void sub(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
602 template<typename Type>
603 inline
void addmul(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
611 template<typename Type>
612 inline
void submul(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
620 template<typename Type>
621 inline
void mul(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
629 template<typename Type>
630 inline
void div(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
640 template<typename Type>
641 inline
void divmod(
NInt<Type> & q,
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
649 template<typename Type>
650 inline
void mod(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
658 template<typename Type>
659 inline
void shl(
NInt<Type> & r, const
NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
667 template<typename Type>
668 inline
void shr(
NInt<Type> & r, const
NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
676 template<typename Type>
677 inline
void shl(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
685 template<typename Type>
686 inline
void shr(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
694 template<typename Type>
695 inline
void increment(
NInt<Type> & r, const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
702 template<typename Type>
703 inline
void decrement(
NInt<Type> & r, const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
710 template<typename Type>
711 inline
void neg(
NInt<Type> & r, const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
718 template<typename Type>
719 inline
void abs(
NInt<Type> & r, const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
726 template<typename Type>
727 inline
void square(
NInt<Type> & r, const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
738 template<typename Type>
739 inline
NInt<Type>
abs(const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
745 template<typename Type>
746 inline
NInt<Type>
square(const
NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
755 template<typename Type>
756 std::ostream & operator << (std::ostream &, const
NInt<Type> &);
761 template<typename Type>
762 std::istream & operator >> (std::istream &,
NInt<Type> &);
771 template<typename Type>
772 inline
void setZero(
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
776 template<typename Type>
777 inline
void setOne(
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
791 template<typename Type>
792 inline
int compare(const
NInt<Type> &, const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
801 template<typename Type>
814 template<typename Type>
815 inline
int sign(const
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
821 template<typename Type>
822 inline
void makeAbs(
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
832 template<typename Type>
833 inline
int bit(const
NInt<Type> & x,
long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
841 template<typename Type>
842 inline
void setbit(
NInt<Type> & x,
long n,
bool value = true) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
854 template<typename Type>
855 inline
NInt<Type>
power(const
NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
863 template<typename Type>
864 inline
void power(
NInt<Type> & r, const
NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
871 template<typename Type>
872 inline
NInt<Type>
power(const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
880 template<typename Type>
881 inline
void power(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
893 template<typename Type>
894 inline
void sqrtCeil(
NInt<Type> & r, const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
901 template<typename Type>
902 inline
NInt<Type>
sqrtCeil(const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
909 template<typename Type>
910 inline
void sqrtFloor(
NInt<Type> & r, const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
917 template<typename Type>
918 inline
NInt<Type>
sqrtFloor(const
NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
926 template<typename Type>
927 long ceilOfLog2(const
NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
935 template<typename Type>
936 long floorOfLog2(const
NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
943 template<typename Type>
944 long approxLog2(const
NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
952 template<typename Type>
953 inline
long bitLength(const
NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
962 template<typename Type>
963 void floorDiv(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
972 template<typename Type>
973 NInt<Type>
floorDiv(const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
982 template<typename Type>
983 void ceilDiv(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
992 template<typename Type>
993 NInt<Type>
ceilDiv(const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1003 template<typename Type>
1004 void roundDiv(
NInt<Type> & r, const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1014 template<typename Type>
1015 NInt<Type>
roundDiv(const
NInt<Type> & a, const
NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1032 template<typename Type>
1045 template<typename Type>
1056 template<typename Type>
1057 inline
void GCD(
NInt<Type> & r, const
NInt<Type> & x, const
NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1066 template<typename Type>
1067 inline
NInt<Type>
GCD(const
NInt<Type> & x, const
NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1082 template<typename Type>
1083 inline
void XGCD(
NInt<Type> & r,
NInt<Type> & a,
NInt<Type> & b, const
NInt<Type> & x, const
NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1093 template<typename Type>
1094 inline
void LCM(
NInt<Type> & r, const
NInt<Type> & x, const
NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1103 template<typename Type>
1104 inline
NInt<Type>
LCM(const
NInt<Type> & x, const
NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1113 template<typename Type>
1114 inline
void swap(
NInt<Type> &,
NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1122 template<typename Type>
1125 #ifdef PLLL_INTERNAL_NO_TEMPLATE_FRIENDS
1131 template<
class X,
class Y>
1139 inline NInt(
bool, Type v) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1144 inline void assignType(Type v) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1158 inline NInt() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1178 inline NInt(
const NInt & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1179 : d_value(i.d_value)
1188 template<
typename T>
1190 : d_value(i.d_value)
1201 : d_value(i.d_value)
1211 template<
typename T>
1213 : d_value(i.d_value)
1231 inline explicit NInt(
double d) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1241 inline explicit NInt(
long double d) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1251 inline explicit NInt(
long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1261 inline explicit NInt(
unsigned long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1281 inline NInt & operator = (
const NInt & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1283 d_value = r.d_value;
1287 #ifndef PLLL_INTERNAL_NO_TEMPLATE_FRIENDS
1289 friend NInt<Type> operator + <>(const NInt<Type> &, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1290 friend NInt<Type> operator - <>(const NInt<Type> &, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1291 friend NInt<Type> operator * <>(const NInt<Type> &, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1292 friend NInt<Type> operator / <>(const NInt<Type> &, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1293 friend NInt<Type> operator % <>(const NInt<Type> &, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1294 friend NInt<Type> operator << <>(const NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1295 friend NInt<Type> operator >> <>(const NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1296 friend NInt<Type> operator << <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1297 friend NInt<Type> operator >> <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1298 friend NInt<Type> & operator -= <>(NInt<Type> &, const NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1299 friend NInt<Type> & operator += <>(NInt<Type> &, const NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1300 friend NInt<Type> & operator *= <>(NInt<Type> &, const NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1301 friend NInt<Type> & operator /= <>(NInt<Type> &, const NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1302 friend NInt<Type> & operator %= <>(NInt<Type> &, const NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1303 friend NInt<Type> operator ++ <>(NInt<Type> &,
int) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1304 friend NInt<Type> operator -- <>(NInt<Type> &,
int) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1305 friend NInt<Type> & operator ++ <>(NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1306 friend NInt<Type> & operator -- <>(NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1307 friend
bool operator == <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1308 friend
bool operator != <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1309 friend
bool operator <= <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1310 friend
bool operator >= <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1311 friend
bool operator < <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1312 friend
bool operator > <>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1313 friend
bool isZero<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1314 friend
bool isOne<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1315 friend
bool isPMOne<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1316 friend
bool isPMTwo<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1317 friend
bool isPositive<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1318 friend
bool isNonNegative<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1319 friend
bool isNegative<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1320 friend
bool isNonPositive<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1321 friend
void add<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1322 friend
void sub<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1323 friend
void mul<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1324 friend
void div<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1325 friend
void mod<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1326 friend
void shl<>(NInt<Type> & r, const NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1327 friend
void shr<>(NInt<Type> & r, const NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1328 friend
void shl<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1329 friend
void shr<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1330 friend
void increment<>(NInt<Type> & r, const NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1331 friend
void decrement<>(NInt<Type> & r, const NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1332 friend
void neg<>(NInt<Type> & r, const NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1333 friend
void abs<>(NInt<Type> & r, const NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1334 friend NInt<Type>
abs<>(const NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1335 friend
void makeAbs<>(NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1336 friend std::ostream & operator << <>(std::ostream & s, const NInt<Type> & r);
1338 friend std::istream & operator >> <>(std::istream & s, NInt<Type> & r);
1340 friend
void setZero<>(NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1342 friend
void setOne<>(NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1344 friend
int compare<>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1346 friend
int compareAbsValues<>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1349 friend
int sign<>(const NInt<Type> & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1351 friend
int bit<>(const NInt<Type> &,
long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1352 friend NInt<Type>
square<>(const NInt<Type> & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1353 friend
void square<>(NInt<Type> & r, const NInt<Type> & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1354 friend NInt<Type>
power<>(const NInt<Type> &,
long) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1355 friend
void power<>(NInt<Type> &, const NInt<Type> &,
long) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1356 friend NInt<Type>
power<>(const NInt<Type> &, const NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1357 friend
void power<>(NInt<Type> &, const NInt<Type> &, const NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1358 friend
void sqrtCeil<>(NInt<Type> &, const NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1359 friend
void sqrtFloor<>(NInt<Type> &, const NInt<Type> &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1360 friend
long ceilOfLog2<>(const NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1361 friend
long floorOfLog2<>(const NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1362 friend
long approxLog2<>(const NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1363 friend
long bitLength<>(const NInt<Type> & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1364 friend
void floorDiv<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1365 friend NInt<Type>
floorDiv<>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1366 friend
void ceilDiv<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1367 friend NInt<Type>
ceilDiv<>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1368 friend
void roundDiv<>(NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1369 friend NInt<Type>
roundDiv<>(const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1370 friend
void euclideanDivision<>(NInt<Type> & q, NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1371 friend
void euclideanDivisionPos<>(NInt<Type> & q, NInt<Type> & r, const NInt<Type> & a, const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1372 friend
void GCD<>(NInt<Type> & r, const NInt<Type> & x, const NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1373 friend NInt<Type>
GCD<>(const NInt<Type> & x, const NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1374 friend
void XGCD<>(NInt<Type> & r, NInt<Type> & a, NInt<Type> & b, const NInt<Type> & x, const NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1375 friend
void LCM<>(NInt<Type> & r, const NInt<Type> & x, const NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1376 friend NInt<Type>
LCM<>(const NInt<Type> & x, const NInt<Type> & y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1377 friend
void swap<>(NInt<Type> & a, NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1381 template<
typename Type>
1387 template<
typename Type>
1390 return NInt<Type>(
true, a.d_value + b.d_value);
1393 template<
typename Type>
1396 return NInt<Type>(
true, a.d_value - b.d_value);
1399 template<
typename Type>
1402 return NInt<Type>(
true, a.d_value * b.d_value);
1405 template<
typename Type>
1408 return NInt<Type>(
true, a.d_value / b.d_value);
1411 template<
typename Type>
1414 return NInt<Type>(
true, a.d_value % b.d_value);
1417 template<
typename Type>
1420 a.d_value -= i.d_value;
1424 template<
typename Type>
1427 a.d_value += i.d_value;
1431 template<
typename Type>
1434 a.d_value *= i.d_value;
1438 template<
typename Type>
1441 a.d_value /= i.d_value;
1445 template<
typename Type>
1448 a.d_value %= i.d_value;
1452 template<
typename Type>
1453 inline NInt<Type> & operator <<= (NInt<Type> & a,
long r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1459 template<
typename Type>
1466 template<
typename Type>
1473 template<
typename Type>
1480 template<
typename Type>
1486 template<
typename Type>
1492 template<
typename Type>
1499 template<
typename Type>
1506 template<
typename Type>
1507 inline NInt<Type> operator << (const NInt<Type> & a,
long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1514 template<
typename Type>
1522 template<
typename Type>
1530 template<
typename Type>
1538 template<
typename Type>
1541 return a.d_value == b.d_value;
1544 template<
typename Type>
1547 return a.d_value != b.d_value;
1550 template<
typename Type>
1551 inline bool operator <= (const NInt<Type> & a,
const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1553 return a.d_value <= b.d_value;
1556 template<
typename Type>
1559 return a.d_value >= b.d_value;
1562 template<
typename Type>
1563 inline bool operator < (const NInt<Type> & a,
const NInt<Type> & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1565 return a.d_value < b.d_value;
1568 template<
typename Type>
1571 return a.d_value > b.d_value;
1574 template<
typename Type>
1578 return r.d_value == (Type)0;
1581 template<
typename Type>
1585 return r.d_value == (Type)1;
1588 template<
typename Type>
1592 return (r.d_value == (Type)1) || (r.d_value == (Type)(-1));
1595 template<
typename Type>
1599 return (r.d_value == (Type)2) || (r.d_value == (Type)(-2));
1602 template<
typename Type>
1606 return r.d_value > (Type)0;
1609 template<
typename Type>
1613 return r.d_value >= (Type)0;
1616 template<
typename Type>
1620 return r.d_value < (Type)0;
1623 template<
typename Type>
1627 return r.d_value <= (Type)0;
1630 template<
typename Type>
1633 r.d_value = a.d_value + b.d_value;
1636 template<
typename Type>
1639 r.d_value = a.d_value - b.d_value;
1642 template<
typename Type>
1645 r.d_value += a.d_value * b.d_value;
1648 template<
typename Type>
1651 r.d_value -= a.d_value * b.d_value;
1654 template<
typename Type>
1657 r.d_value = a.d_value * b.d_value;
1660 template<
typename Type>
1663 r.d_value = a.d_value / b.d_value;
1666 template<
typename Type>
1669 r.d_value = a.d_value % b.d_value;
1672 template<
typename Type>
1675 Type qq = a.d_value / b.d_value, rr = a.d_value % b.d_value;
1680 template<
typename Type>
1685 if (static_cast<unsigned long>(-b) >= static_cast<unsigned long>(std::numeric_limits<Type>::digits))
1688 r.d_value = a.d_value >>
static_cast<unsigned long>(-b);
1692 if (b >= std::numeric_limits<Type>::digits)
1695 r.d_value = a.d_value << b;
1699 template<
typename Type>
1704 if (static_cast<unsigned long>(-b) >= static_cast<unsigned long>(std::numeric_limits<Type>::digits))
1707 r.d_value = a.d_value <<
static_cast<unsigned long>(-b);
1711 if (b >= std::numeric_limits<Type>::digits)
1714 r.d_value = a.d_value >> b;
1718 template<
typename Type>
1721 r.d_value = a.d_value << b.d_value;
1724 template<
typename Type>
1727 if (b.d_value >= std::numeric_limits<Type>::digits)
1730 r.d_value = a.d_value >> b.d_value;
1733 template<
typename Type>
1736 r.d_value = a.d_value + (Type)1;
1739 template<
typename Type>
1742 r.d_value = a.d_value - (Type)1;
1745 template<
typename Type>
1748 r.d_value = -a.d_value;
1751 template<
typename Type>
1754 r.d_value = a.d_value < 0 ? -a.d_value : a.d_value;
1757 template<
typename Type>
1760 return NInt<Type>(
true, i.d_value < 0 ? -i.d_value : i.d_value);
1763 template<
typename Type>
1767 a.d_value = -a.d_value;
1770 template<
typename Type>
1771 std::ostream & operator << (std::ostream & s, const NInt<Type> & r)
1774 return s << r.d_value;
1777 template<
typename Type>
1781 return s >> r.d_value;
1784 template<
typename Type>
1788 r.d_value = (Type)0;
1791 template<
typename Type>
1795 r.d_value = (Type)1;
1798 template<
typename Type>
1802 return a.d_value < b.d_value ? -1 : (a.d_value > b.d_value ? 1 : 0);
1805 template<
typename Type>
1810 Type aabs = a.d_value < 0 ? -a.d_value : a.d_value, babs = b.d_value < 0 ? -b.d_value : b.d_value;
1811 return aabs < babs ? -1 : (aabs > babs ? 1 : 0);
1814 template<
typename Type>
1818 return r.d_value < 0 ? -1 : (r.d_value > 0 ? 1 : 0);
1821 namespace implementation
1823 template<
typename Type>
1829 typedef unsigned int result;
1835 typedef unsigned long result;
1841 typedef unsigned long long result;
1845 template<
typename Type>
1846 inline int bit(
const NInt<Type> & v,
long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1849 return v.d_value < 0
1851 : ((v.d_value >> (Type)n) & 1);
1854 template<
typename Type>
1859 v.d_value |= (
static_cast<Type
>(1) << n);
1861 v.d_value &= ~(
static_cast<Type
>(1) << n);
1864 template<
typename Type>
1867 return NInt<Type>(
true, i.d_value * i.d_value);
1870 template<
typename Type>
1873 r.d_value = a.d_value * a.d_value;
1876 template<
typename Type>
1877 inline Type powerimpl(Type base, Type
exp) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1880 Type result = (
exp & 1) ? base : (Type)1;
1892 template<
typename Type>
1895 r.d_value = powerimpl(a.d_value, (Type)e);
1898 template<
typename Type>
1901 return NInt<Type>(
true, powerimpl(a.d_value, (Type)e));
1904 template<
typename Type>
1907 r.d_value = powerimpl(a.d_value, e.d_value);
1910 template<
typename Type>
1913 return NInt<Type>(
true, powerimpl(a.d_value, e.d_value));
1916 template<
typename Type>
1919 Type result = 0, rsq = 0, bm = 1;
1921 while (bm + (bm - 1) < a.d_value)
1928 Type nsq = rsq + bm + (result << (bits + 1));
1929 if (nsq <= a.d_value)
1931 result += (((Type)1) << bits);
1937 v.d_value = (rsq < a.d_value) ? result + 1 : result;
1940 template<
typename Type>
1943 Type result = 0, rsq = 0, bm = 1;
1945 while (bm + (bm - 1) < a.d_value)
1952 Type nsq = rsq + bm + (result << (bits + 1));
1953 if (nsq <= a.d_value)
1955 result += (((Type)1) << bits);
1964 template<
typename Type>
1968 Type v = x.d_value < 0 ? -x.d_value : x.d_value;
1969 bool pot = (v & (-v)) == v;
1981 template<
typename Type>
1985 Type v = x.d_value < 0 ? -x.d_value : x.d_value;
1995 namespace implementation
2002 typedef signed short int signed_type;
2003 typedef unsigned short int unsigned_type;
2004 enum { is_signed =
true };
2010 typedef signed int signed_type;
2011 typedef unsigned int unsigned_type;
2012 enum { is_signed =
true };
2018 typedef signed long signed_type;
2019 typedef unsigned long unsigned_type;
2020 enum { is_signed =
true };
2026 typedef signed long long signed_type;
2027 typedef unsigned long long unsigned_type;
2028 enum { is_signed =
true };
2034 typedef signed short int signed_type;
2035 typedef unsigned short int unsigned_type;
2036 enum { is_signed =
false };
2042 typedef signed int signed_type;
2043 typedef unsigned int unsigned_type;
2044 enum { is_signed =
false };
2050 typedef signed long signed_type;
2051 typedef unsigned long unsigned_type;
2052 enum { is_signed =
false };
2058 typedef signed long long signed_type;
2059 typedef unsigned long long unsigned_type;
2060 enum { is_signed =
false };
2063 template<
class UType>
2064 inline long approxLog2Impl(UType xx) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2070 unsigned int res, shift;
2072 (std::numeric_limits<UType>::digits == 8) ||
2073 (std::numeric_limits<UType>::digits == 15) ||
2074 (std::numeric_limits<UType>::digits == 16) ||
2075 (std::numeric_limits<UType>::digits == 31) ||
2076 (std::numeric_limits<UType>::digits == 32) ||
2077 (std::numeric_limits<UType>::digits == 63) ||
2078 (std::numeric_limits<UType>::digits == 64) ||
2079 (std::numeric_limits<UType>::digits == 127) ||
2080 (std::numeric_limits<UType>::digits == 128), RequiresTypeOf_8_16_32_64_128_Bits)
2081 switch (std::numeric_limits<UType>::digits)
2087 res = (xx > (UType)0xF) << 2; xx >>= res;
2088 shift = (xx > (UType)0x3) << 1; xx >>= shift; res |= shift;
2089 res |= (xx >> (UType)1);
2095 res = (xx > (UType)0xFF) << 3; xx >>= res;
2096 shift = (xx > (UType)0xF ) << 2; xx >>= shift; res |= shift;
2097 shift = (xx > (UType)0x3 ) << 1; xx >>= shift; res |= shift;
2098 res |= (xx >> (UType)1);
2104 res = (xx > (UType)0xFFFF) << 4; xx >>= res;
2105 shift = (xx > (UType)0xFF ) << 3; xx >>= shift; res |= shift;
2106 shift = (xx > (UType)0xF ) << 2; xx >>= shift; res |= shift;
2107 shift = (xx > (UType)0x3 ) << 1; xx >>= shift; res |= shift;
2108 res |= (xx >> (UType)1);
2114 res = (xx > (UType)0xFFFFFFFFul) << 5; xx >>= res;
2115 shift = (xx > (UType)0xFFFF ) << 4; xx >>= shift; res |= shift;
2116 shift = (xx > (UType)0xFF ) << 3; xx >>= shift; res |= shift;
2117 shift = (xx > (UType)0xF ) << 2; xx >>= shift; res |= shift;
2118 shift = (xx > (UType)0x3 ) << 1; xx >>= shift; res |= shift;
2119 res |= (xx >> (UType)1);
2125 res = (xx > (UType)0xFFFFFFFFFFFFFFFFul) << 6; xx >>= res;
2126 shift = (xx > (UType)0xFFFFFFFFul ) << 5; xx >>= shift; res |= shift;
2127 shift = (xx > (UType)0xFFFF ) << 4; xx >>= shift; res |= shift;
2128 shift = (xx > (UType)0xFF ) << 3; xx >>= shift; res |= shift;
2129 shift = (xx > (UType)0xF ) << 2; xx >>= shift; res |= shift;
2130 shift = (xx > (UType)0x3 ) << 1; xx >>= shift; res |= shift;
2131 res |= (xx >> (UType)1);
2137 template<
typename Type>
2138 inline long approxLog2_impl(Type x, helper::BoolToType<true>) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2141 typedef typename GetUnsignedType<Type>::unsigned_type UType;
2142 return approxLog2Impl(x < 0 ? -(UType)x : (UType)x);
2145 template<
typename Type>
2146 inline long approxLog2_impl(Type x, helper::BoolToType<false>) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2149 return approxLog2Impl(x);
2153 template<
typename Type>
2154 inline long approxLog2(Type x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2157 return implementation::approxLog2_impl(x, helper::BoolToType<implementation::GetUnsignedType<Type>::is_signed>());
2160 template<
typename Type>
2167 template<
typename Type>
2174 template<
typename Type>
2178 Type aa = a.d_value < 0 ? -a.d_value : a.d_value;
2179 Type ba = b.d_value < 0 ? -b.d_value : b.d_value;
2180 bool neg = (b.d_value < 0) ^ (a.d_value < 0);
2182 r.d_value = -(aa + (ba - 1)) / ba;
2184 r.d_value = aa / ba;
2187 template<
typename Type>
2195 template<
typename Type>
2199 Type aa = a.d_value < 0 ? -a.d_value : a.d_value;
2200 Type ba = b.d_value < 0 ? -b.d_value : b.d_value;
2201 bool neg = (b.d_value < 0) ^ (a.d_value < 0);
2203 r.d_value = -aa / ba;
2205 r.d_value = (aa + (ba - 1)) / ba;
2208 template<
typename Type>
2216 template<
typename Type>
2220 Type aa = a.d_value < 0 ? -a.d_value : a.d_value;
2221 Type ba = b.d_value < 0 ? -b.d_value : b.d_value;
2222 bool neg = (b.d_value < 0) ^ (a.d_value < 0);
2224 r.d_value = -(aa + ba/2) / ba;
2226 r.d_value = (aa + ba/2) / ba;
2229 template<
typename Type>
2237 template<
typename Type>
2241 q.d_value = a.d_value / b.d_value;
2242 r.d_value = a.d_value % b.d_value;
2245 template<
typename Type>
2249 Type aa = a.d_value < 0 ? -a.d_value : a.d_value;
2250 Type ba = b.d_value < 0 ? -b.d_value : b.d_value;
2251 bool neg = (b.d_value < 0) ^ (a.d_value < 0);
2253 q.d_value = -(aa + (ba - 1)) / ba;
2255 q.d_value = aa / ba;
2256 r.d_value = a.d_value - q.d_value * b.d_value;
2259 template<
typename Type>
2263 Type a = x.d_value, b = y.d_value;
2277 template<
typename Type>
2285 template<
typename Type>
2289 Type aa = x.d_value, bb = y.d_value;
2290 Type x1, x2 = 0, y1 = 0, y2;
2307 Type r = bb % aa, q = bb / aa;
2317 Type x = x2 - q * x1;
2320 Type y = y2 - q * y1;
2329 template<
typename Type>
2333 r.d_value = x.d_value * (y.d_value / r.d_value);
2336 template<
typename Type>
2344 namespace implementation
2346 void randomInt(
int & l,
long b, RandomNumberGenerator & rng);
2347 void randomInt(
long & l,
long b, RandomNumberGenerator & rng);
2348 void randomInt(
long long & ll,
long long b, RandomNumberGenerator & rng);
2349 void randomBits(
int & l,
unsigned long b, RandomNumberGenerator & rng);
2350 void randomBits(
long & l,
unsigned long b, RandomNumberGenerator & rng);
2351 void randomBits(
long long & ll,
unsigned long b, RandomNumberGenerator & rng);
2354 template<
class IType>
2357 implementation::randomInt(res.d_value, bound.d_value, d_rng);
2360 template<
class IType>
2363 implementation::randomBits(res.d_value, bits, d_rng);
2366 template<
class IType>
2371 randomBits(res, bits - 1);
2380 template<
typename Type>
void randomLen(NInt< IType > &res, unsigned long bits)
Creates a random integer of a fixed bit length.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::FloorDivOp > floorDiv(const Integer &a, const Integer &b)
Computes and returns .
void submul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and subtracts the result from r.
void euclideanDivisionPos(Integer &q, Integer &r, const Integer &a, const Integer &b)
Computes an Euclidean Division of a by b.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ExpOp > exp(const Real &i)
Returns the exponential function evaluated at the given floating point number.
Integer & operator+=(Integer &cur, const expressions::Expression< IntegerContext, D, expressions::MulOp > &E)
Adds the given multiplication expression to cur.
bool isZero(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being zero.
NInt(const Integer &i)
Creates a native CPU integer from the given arbitrary precision integer.
A uniform random number generator frontend.
NInt(long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a native CPU integer from the given native integer.
NInt(const NInt< T > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a copy of the given integer (of another native type).
Integer & operator%=(Integer &cur, const Integer &i)
Divides cur by the given integer i and stores the remainder in cur.
bool isPMTwo(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being two or minus two.
NInt< IType > randomLen(unsigned long bits, const NIntContext< IType > &ic)
Creates a random integer of a fixed bit length.
int bit(const Integer &x, long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the n bit of in the usual binary representation.
void XGCD(Integer &r, Integer &a, Integer &b, const Integer &x, const Integer &y)
Computes the non-negative extended Greatest Common Divisior r of x and y.
int compare(const Integer &a, const Integer &b)
Compares the two integers.
bool isNegative(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being strictly negative.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::NegOp > operator-(const Integer &a)
Negates the integer.
void setOne(Integer &)
Sets the given integer to one.
void shr(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SqrtFloorOp > sqrtFloor(const Integer &i)
Computes and returns the floor of the square root of i.
bool isOne(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being one.
#define PLLL_INTERNAL_STATIC_CHECK(condition, IdentifierWhichIsAMessage)
arithmetic::NInt< IType > Integer
The integer type.
Integer & operator*=(Integer &cur, const Integer &i)
Multiplies the given integer i with cur.
Integer operator--(Integer &cur, int)
Decrements the integer by one and returns the previous value.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::AbsOp > abs(const Integer &i)
Computes and returns the absolute value of i.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::LCMOp > LCM(const Integer &a, const Integer &b)
Computes and returns the non-negative Least Common Multiple of a and b.
Conversion definitions for native integers.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::CeilDivOp > ceilDiv(const Integer &a, const Integer &b)
Computes and returns .
long approxLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Quickly approximates and returns the approximation.
void random(NInt< IType > &res, const NInt< IType > &bound)
Creates a random native CPU integer in the range .
Integer & operator-=(Integer &cur, const expressions::Expression< IntegerContext, D, expressions::MulOp > &E)
Subtracts the multiplication expression E from cur.
NInt(const NIntContext< Type > &c) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new integer. Default value is zero.
void setZero(Integer &)
Sets the given integer to zero.
void mul(Integer &r, const Integer &a, const Integer &b)
Multiplies a with b and stores the result in r.
Provides conversion implementation from type SourceType to DestContext::Type.
void div(Integer &r, const Integer &a, const Integer &b)
Divides a by b and stores the result in r.
NInt(const NInt &i, const NIntContext< Type > &ic) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a copy of the given integer.
void convert(typename DestContext::Type &dst, const SourceType &src, const DestContext &context)
Converts the value in src to the type described by context and stores the result in dst...
NInt< IType > randomBits(unsigned long bits, const NIntContext< IType > &ic)
Creates random bits.
void mod(Integer &r, const Integer &a, const Integer &b)
Takes the remainder of the division of a by b and stores it in r.
void increment(Integer &r, const Integer &a)
Increments a by one and stores the result in r.
bool operator==(const Integer &a, const Integer &b)
Compares the current integer with the given one for equality.
NInt() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new integer. Default value is zero.
Integer & operator/=(Integer &cur, const Integer &i)
Divides cur by the given integer i.
NInt(double d) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a native CPU integer from the given native floating point number.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::MulOp > operator*(const Integer &a, const Integer &b)
Multiplies the two integers and returns the result.
Implementation backend for conversions from context types to native types.
Represents a random number generator.
NInt< IType > random(const NInt< IType > &bound, const NIntContext< IType > &ic)
Creates and returns a random native CPU integer in the range .
void swap(NInt< Type > &, NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Swaps two plll::arithmetic::NInt<> objects.
void swap(plll::arithmetic::Integer &, plll::arithmetic::Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Swaps two plll::arithmetic::Integer objects.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::PowerOp > power(const Integer &a, const Integer &b)
Computes and returns a raised to the power of b.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SqrtCeilOp > sqrtCeil(const Integer &i)
Computes and returns the ceil of the square root of i.
UniformRNG(RandomNumberGenerator &rng) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new uniform random number generator based on the given random number generator.
NInt(const NInt< T > &i, const NIntContext< Type > &ic) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a copy of the given integer (of another native type).
void setbit(Integer &x, long n, bool value=true)
Sets the n-th bit of to value.
Represents a native integer.
NIntContext< Type > Context
The context type.
void randomBits(NInt< IType > &res, unsigned long bits)
Creates random bits.
int compareAbsValues(const Integer &a, const Integer &b)
Compares the two integers in absolute value.
bool isNonNegative(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being positive or zero.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::RoundDivOp > roundDiv(const Integer &a, const Integer &b)
Computes and returns .
int sign(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the sign of the given integer.
NInt(unsigned long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a native CPU integer from the given native integer.
Integer operator++(Integer &cur, int)
Increments the integer by one and returns the previous value.
bool operator>(const Integer &a, const Integer &b)
Compares the current integer with the given one.
void shl(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
static void setContext(const NIntContext< Type > &c) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Sets the integer context c.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::ShROp > operator>>(const Integer &a, const Integer &b)
Computes the bitwise right shift of the first integer by the number of bits given by the second integ...
void neg(Integer &r, const Integer &a)
Negates a and stores the result in r.
void addmul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and adds the result to r.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::ModOp > operator%(const Integer &a, const Integer &b)
Divides the first by the second integer and returns the remainder.
Integer & operator>>=(Integer &cur, const Integer &i)
Computes the bitwise right shift of cur by i bits, and stores the result in cur.
bool isPositive(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being strictly positive.
void divmod(Integer &q, Integer &r, const Integer &a, const Integer &b)
Stores quotient and remainder of the division of a by b in q respectively r.
void add(Integer &r, const Integer &a, const Integer &b)
Adds a and b and stores the result in r.
void makeAbs(Integer &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Makes the operand non-negative.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SquareOp > square(const Integer &i)
Computes and returns the square of i.
void decrement(Integer &r, const Integer &a)
Decrements a by one and stores the result in r.
long bitLength(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns n such that .
long floorOfLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns .
NInt(const NInt &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a copy of the given integer.
bool isNonPositive(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being negative or zero.
long ceilOfLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns .
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::AddOp > operator+(const Integer &a, const Integer &b)
Adds the two integers and returns the result.
Provides information on arithmetic (and string) types.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::DivOp > operator/(const Integer &a, const Integer &b)
Divides the first by the second integer and returns the result.
Represents an arbitrary precision integer.
bool isPMOne(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being one or minus one.
void euclideanDivision(Integer &q, Integer &r, const Integer &a, const Integer &b)
Computes an Euclidean Division of a by b.
bool operator!=(const Integer &a, const Integer &b)
Compares the current integer with the given one for inequality.
Represents an arithmetic context for native integers.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::GCDOp > GCD(const Integer &a, const Integer &b)
Computes and returns the non-negative Greatest Common Divisor of a and b.
NInt(long double d) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a native CPU integer from the given native floating point number.
bool operator>=(const Integer &a, const Integer &b)
Compares the current integer with the given one.
arithmetic::NInt< IType > Type
The integer type.
void sub(Integer &r, const Integer &a, const Integer &b)
Subtracts b from a and stores the result in r.