23 #ifndef PLLL_INCLUDE_GUARD__ARITHMETIC_GMP_HPP
24 #define PLLL_INCLUDE_GUARD__ARITHMETIC_GMP_HPP
26 #include <plll/config.hpp>
44 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
47 extern bool Real_precision_check_enabled;
50 inline void Real_precision_check_disable() { arithmetic::internal::Real_precision_check_enabled =
false; }
51 inline void Real_precision_check_enable() { arithmetic::internal::Real_precision_check_enabled =
true; }
53 inline void Real_precision_check_disable() { }
54 inline void Real_precision_check_enable() { }
60 #define MPFR_USE_INTMAX_T 1
77 #if (MPFR_VERSION <= 0x0204FF)
79 #define MPFR_RNDN GMP_RNDN
80 #define MPFR_RNDZ GMP_RNDZ
81 #define MPFR_RNDU GMP_RNDU
82 #define MPFR_RNDD GMP_RNDD
83 typedef mp_exp_t mpfr_exp_t;
85 #if (__GMP_MP_RELEASE < 50000)
87 typedef unsigned long mp_bitcnt_t;
106 void swap(plll::arithmetic::Real &, plll::arithmetic::Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
133 inline
bool isZero(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
141 inline
bool isZero(const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
149 inline
bool isOne(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
157 inline
bool isPMOne(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
165 inline
bool isPMTwo(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
173 inline
bool isOne(const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
181 inline
bool isPositive(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
189 inline
bool isPositive(const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
197 inline
bool isNonNegative(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
205 inline
bool isNonNegative(const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
213 inline
bool isNegative(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
221 inline
bool isNegative(const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
229 inline
bool isNonPositive(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
237 inline
bool isNonPositive(const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
254 inline
void euclideanDivision(Integer & q, Integer & r, const Integer & a, const Integer & b);
266 inline
void euclideanDivisionPos(Integer & q, Integer & r, const Integer & a, const Integer & b);
276 inline
void GCD(Integer & r, const Integer & x, const Integer & y);
291 inline
void XGCD(Integer & r, Integer & a, Integer & b, const Integer & x, const Integer & y);
301 inline
void LCM(Integer & r, const Integer & x, const Integer & y);
310 std::ostream & operator << (std::ostream &, const Integer &);
314 std::istream & operator >> (std::istream &, Integer &);
318 std::ostream & operator << (std::ostream &, const Real &);
322 std::istream & operator >> (std::istream &, Real &);
331 inline
void setNaN(Real &);
343 inline
void setZero(Integer &);
355 inline
void setOne(Integer &);
359 inline
void setOne(Real &);
373 inline
int compare(const Integer & a, const Integer & b);
382 inline
int compare(const Real & a, const Real & b);
412 inline
int sign(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
420 inline
int sign(const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
430 inline
int bit(const Integer & x,
long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
438 inline
void setbit(Integer & x,
long n,
bool value = true);
451 inline
void increment(Integer & r, const Integer & a);
458 inline
void decrement(Integer & r, const Integer & a);
466 inline
void add(Integer & r, const Integer & a, const Integer & b);
474 inline
void sub(Integer & r, const Integer & a, const Integer & b);
482 inline
void mul(Integer & r, const Integer & a, const Integer & b);
489 inline
void neg(Integer & r, const Integer & a);
497 inline
void div(Integer & r, const Integer & a, const Integer & b);
505 inline
void mod(Integer & r, const Integer & a, const Integer & b);
515 inline
void divmod(Integer & q, Integer & r, const Integer & a, const Integer & b);
522 inline
void abs(Integer & r, const Integer & a);
530 inline
void addmul(Integer & r, const Integer & a, const Integer & b);
538 inline
void submul(Integer & r, const Integer & a, const Integer & b);
546 inline
void band(Integer & r, const Integer & a, const Integer & b);
554 inline
void bor(Integer & r, const Integer & a, const Integer & b);
562 inline
void bxor(Integer & r, const Integer & a, const Integer & b);
569 inline
void bneg(Integer & r, const Integer & a);
577 inline
void shl(Integer & r, const Integer & a,
long b);
585 inline
void shl(Integer & r, const Integer & a, const Integer & b);
593 inline
void shr(Integer & r, const Integer & a,
long b);
601 inline
void shr(Integer & r, const Integer & a, const Integer & b);
608 inline
void square(Integer & r, const Integer & a);
617 inline
void add(Real & r, const Real & a, const Real & b);
625 inline
void sub(Real & r, const Real & a, const Real & b);
633 inline
void mul(Real & r, const Real & a, const Real & b);
641 inline
void div(Real & r, const Real & a, const Real & b);
649 inline
void mod(Real & r, const Real & a, const Real & b);
659 inline
void divmod(Real & q, Real & r, const Real & a, const Real & b);
667 inline
void shl(Real & r, const Real & a, const Real & b);
677 inline
void shr(Real & r, const Real & a, const Real & b);
687 inline
void shl(Real & r, const Real & a,
long b);
695 inline
void shr(Real & r, const Real & a,
long b);
702 inline
void increment(Real & r, const Real & a);
709 inline
void decrement(Real & r, const Real & a);
716 inline
void neg(Real & r, const Real & a);
723 inline
void abs(Real & r, const Real & a);
731 inline
void addmul(Real & r, const Real & a, const Real & b);
739 inline
void submul(Real & r, const Real & a, const Real & b);
746 inline
void square(Real & r, const Real & a);
756 inline
void makeAbs(Integer & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
762 inline
void makeAbs(Real & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
775 inline
void power(Integer & r, const Integer & a,
long b);
783 inline
void power(Integer & r, const Integer & a, const Integer & b);
795 inline
void sqrtCeil(Integer & r, const Integer & a);
802 inline
void sqrtFloor(Integer & r, const Integer & a);
810 long approxLog2(const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
818 long ceilOfLog2(const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
826 long floorOfLog2(const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
834 inline
long bitLength(const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
844 void floorDiv(Integer & r, const Integer & a, const Integer & b);
853 void ceilDiv(Integer & r, const Integer & a, const Integer & b);
863 void roundDiv(Integer & r, const Integer & a, const Integer & b);
876 inline
void sin(Real & res, const Real & a);
884 inline
void cos(Real & res, const Real & a);
892 inline
void tan(Real & res, const Real & a);
900 inline
void asin(Real & res, const Real & a);
908 inline
void acos(Real & res, const Real & a);
916 inline
void atan(Real & res, const Real & a);
927 inline
void atan2(Real & res, const Real & y, const Real & x);
940 inline
void exp(Real & res, const Real & a);
947 inline
void log(Real & res, const Real & a);
954 inline
void log2(Real & res, const Real & a);
961 inline
void log10(Real & res, const Real & a);
968 inline
void sqrt(Real & res, const Real & a);
981 inline
void gamma(Real & res, const Real & a);
990 inline
void lgamma(Real & res, const Real & a);
1001 inline
void lgamma(Real & res,
int &
sign, const Real & a);
1015 inline
void power(Real & res, const Real & a,
long b);
1023 inline
void power(Real & res, const Real & a, const Integer & b);
1032 inline
void power(Real & res, const Real & a, const Real & b);
1057 enum { is_cputype =
false, is_realtype =
false, is_inttype =
true, is_exact =
true,
1058 is_modulo =
false, has_infinity =
false, has_uniform_rng =
true };
1076 #ifndef PLLL_INTERNAL_NO_TEMPLATE_FRIENDS
1077 template<
class X,
class Y>
1090 static void mpz_init_set_ld(mpz_t &,
long double);
1091 static void mpz_set_ld(mpz_t &,
long double);
1092 static long double mpz_get_ld(
const mpz_t &);
1093 static void mpz_set_ll(mpz_t &,
long long);
1094 static long long mpz_get_ll(
const mpz_t &);
1127 mpz_init_set(d_value, i.d_value);
1136 inline Integer(
const Integer & i,
const IntegerContext & ic)
1138 mpz_init_set(d_value, i.d_value);
1148 mpz_init_set_si(d_value, i);
1158 mpz_init_set_ui(d_value, i);
1168 mpz_init_set_si(d_value, i);
1178 mpz_init_set_ui(d_value, i);
1189 mpz_set_ll(d_value, i);
1200 mpz_init_set_d(d_value, d);
1211 mpz_init_set_ld(d_value, d);
1219 template<
class A,
template<
typename,
typename>
class O>
1232 template<
class A,
template<
typename,
typename>
class O>
1244 #if __cplusplus >= 201103L
1245 if (d_value[0]._mp_d != NULL)
1250 #if __cplusplus >= 201103L
1256 inline Integer(Integer && i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1257 : d_value{i.d_value[0]}
1259 i.d_value[0]._mp_d = NULL;
1267 inline Integer &
operator = (Integer && i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1270 d_value[0] = i.d_value[0];
1271 i.d_value[0]._mp_d = NULL;
1281 explicit Integer(
const Real & r);
1297 mpz_set(d_value, i.d_value);
1302 template<
class A,
template<
typename,
typename>
class O>
1309 inline friend void increment(Integer & r,
const Integer & a)
1311 mpz_add_ui(r.d_value, a.d_value, 1);
1314 inline friend void decrement(Integer & r,
const Integer & a)
1316 mpz_sub_ui(r.d_value, a.d_value, 1);
1319 inline friend void add(Integer & r,
const Integer & a,
const Integer & b)
1321 mpz_add(r.d_value, a.d_value, b.d_value);
1324 inline friend void add_ui(Integer & r,
const Integer & a,
unsigned long b)
1327 mpz_add_ui(r.d_value, a.d_value, b);
1330 inline friend void add_si(Integer & r,
const Integer & a,
signed long b)
1334 mpz_sub_ui(r.d_value, a.d_value, -b);
1336 mpz_add_ui(r.d_value, a.d_value, b);
1339 inline friend void sub(Integer & r,
const Integer & a,
const Integer & b)
1341 mpz_sub(r.d_value, a.d_value, b.d_value);
1344 inline friend void sub_ui(Integer & r,
const Integer & a,
unsigned long b)
1347 mpz_sub_ui(r.d_value, a.d_value, b);
1350 inline friend void sub_si(Integer & r,
const Integer & a,
signed long b)
1354 mpz_add_ui(r.d_value, a.d_value, -b);
1356 mpz_sub_ui(r.d_value, a.d_value, b);
1359 inline friend void ui_sub(Integer & r,
unsigned long a,
const Integer & b)
1362 mpz_ui_sub(r.d_value, a, b.d_value);
1365 inline friend void si_sub(Integer & r,
signed long a,
const Integer & b)
1370 mpz_add_ui(r.d_value, b.d_value, -a);
1371 mpz_neg(r.d_value, r.d_value);
1374 mpz_ui_sub(r.d_value, a, b.d_value);
1377 inline friend void mul(Integer & r,
const Integer & a,
const Integer & b)
1379 mpz_mul(r.d_value, a.d_value, b.d_value);
1382 inline friend void mul_ui(Integer & r,
const Integer & a,
unsigned long b)
1385 mpz_mul_ui(r.d_value, a.d_value, b);
1388 inline friend void mul_si(Integer & r,
const Integer & a,
signed long b)
1391 mpz_mul_si(r.d_value, a.d_value, b);
1394 inline friend void neg(Integer & r,
const Integer & a)
1396 mpz_neg(r.d_value, a.d_value);
1399 inline friend void div(Integer & r,
const Integer & a,
const Integer & b)
1401 mpz_tdiv_q(r.d_value, a.d_value, b.d_value);
1404 inline friend void div_ui(Integer & r,
const Integer & a,
unsigned long b)
1407 mpz_tdiv_q_ui(r.d_value, a.d_value, b);
1410 inline friend void div_si(Integer & r,
const Integer & a,
signed long b)
1415 mpz_tdiv_q_ui(r.d_value, a.d_value, -b);
1416 mpz_neg(r.d_value, r.d_value);
1419 mpz_tdiv_q_ui(r.d_value, a.d_value, b);
1422 inline friend void mod(Integer & r,
const Integer & a,
const Integer & b)
1424 mpz_tdiv_r(r.d_value, a.d_value, b.d_value);
1427 inline friend void mod_ui(Integer & r,
const Integer & a,
unsigned long b)
1430 mpz_tdiv_r_ui(r.d_value, a.d_value, b);
1433 inline friend void mod_si(Integer & r,
const Integer & a,
signed long b)
1436 mpz_tdiv_r_ui(r.d_value, a.d_value, (b < 0) ? -b : b);
1439 inline friend void divmod(Integer & q, Integer & r,
const Integer & a,
const Integer & b)
1441 mpz_tdiv_qr(q.d_value, r.d_value, a.d_value, b.d_value);
1444 inline friend void divmod_ui(Integer & q, Integer & r,
const Integer & a,
unsigned long b)
1447 mpz_tdiv_qr_ui(q.d_value, r.d_value, a.d_value, b);
1450 inline friend void divmod_si(Integer & q, Integer & r,
const Integer & a,
signed long b)
1453 mpz_tdiv_qr_ui(q.d_value, r.d_value, a.d_value, (b < 0) ? -b : b);
1455 mpz_neg(q.d_value, q.d_value);
1458 inline friend void abs(Integer & r,
const Integer & a)
1460 mpz_abs(r.d_value, a.d_value);
1463 inline friend void addmul(Integer & r,
const Integer & a,
const Integer & b)
1465 mpz_addmul(r.d_value, a.d_value, b.d_value);
1468 inline friend void addmul_ui(Integer & r,
const Integer & a,
unsigned long b)
1471 mpz_addmul_ui(r.d_value, a.d_value, b);
1474 inline friend void addmul_si(Integer & r,
const Integer & a,
signed long b)
1478 mpz_submul_ui(r.d_value, a.d_value, -b);
1480 mpz_addmul_ui(r.d_value, a.d_value, b);
1483 inline friend void submul(Integer & r,
const Integer & a,
const Integer & b)
1485 mpz_submul(r.d_value, a.d_value, b.d_value);
1488 inline friend void submul_ui(Integer & r,
const Integer & a,
unsigned long b)
1491 mpz_submul_ui(r.d_value, a.d_value, b);
1494 inline friend void submul_si(Integer & r,
const Integer & a,
signed long b)
1498 mpz_addmul_ui(r.d_value, a.d_value, -b);
1500 mpz_submul_ui(r.d_value, a.d_value, b);
1503 inline friend void power(Integer & r,
const Integer & a,
long b)
1506 mpz_set_ui(r.d_value, 0);
1508 mpz_pow_ui(r.d_value, a.d_value, b);
1511 inline friend void power(Integer & r,
const Integer & a,
const Integer & b)
1514 mpz_set_ui(r.d_value, 0);
1516 mpz_pow_ui(r.d_value, a.d_value, mpz_get_ui(b.d_value));
1519 inline friend void floorDiv(Integer & r,
const Integer & a,
const Integer & b)
1521 mpz_fdiv_q(r.d_value, a.d_value, b.d_value);
1524 inline friend void ceilDiv(Integer & r,
const Integer & a,
const Integer & b)
1526 mpz_cdiv_q(r.d_value, a.d_value, b.d_value);
1529 inline friend void roundDiv(Integer & r,
const Integer & a,
const Integer & b)
1533 mpz_fdiv_qr(r.d_value, rem, a.d_value, b.d_value);
1534 mpz_mul_2exp(rem, rem, 1);
1535 if (mpz_cmp(rem, b.d_value) > 0)
1536 mpz_add_ui(r.d_value, r.d_value, 1);
1540 inline friend void sqrtCeil(Integer & r,
const Integer & a)
1544 mpz_sqrtrem(r.d_value, rr, a.d_value);
1545 if (mpz_sgn(rr) != 0)
1550 inline friend void sqrtFloor(Integer & r,
const Integer & a)
1552 mpz_sqrt(r.d_value, a.d_value);
1555 inline friend void band(Integer & r,
const Integer & a,
const Integer & b)
1557 mpz_and(r.d_value, a.d_value, b.d_value);
1560 inline friend void bor(Integer & r,
const Integer & a,
const Integer & b)
1562 mpz_ior(r.d_value, a.d_value, b.d_value);
1565 inline friend void bxor(Integer & r,
const Integer & a,
const Integer & b)
1567 mpz_xor(r.d_value, a.d_value, b.d_value);
1570 inline friend void bneg(Integer & r,
const Integer & a)
1572 mpz_com(r.d_value, a.d_value);
1575 inline friend void shl(Integer & r,
const Integer & a,
long b)
1578 mpz_tdiv_q_2exp(r.d_value, a.d_value, -b);
1580 mpz_mul_2exp(r.d_value, a.d_value, b);
1583 inline friend void shl(Integer & r,
const Integer & a,
const Integer & b)
1585 mpz_mul_2exp(r.d_value, a.d_value, mpz_get_ui(b.d_value));
1588 inline friend void shr(Integer & r,
const Integer & a,
long b)
1591 mpz_mul_2exp(r.d_value, a.d_value, -b);
1593 mpz_tdiv_q_2exp(r.d_value, a.d_value, b);
1596 inline friend void shr(Integer & r,
const Integer & a,
const Integer & b)
1598 mpz_tdiv_q_2exp(r.d_value, a.d_value, mpz_get_ui(b.d_value));
1601 inline friend bool isZero(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1603 return mpz_sgn(i.d_value) == 0;
1606 inline friend bool isOne(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1608 return mpz_cmp_ui(i.d_value, 1) == 0;
1611 inline friend bool isPMOne(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1613 return mpz_cmpabs_ui(i.d_value, 1) == 0;
1616 inline friend bool isPMTwo(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1618 return mpz_cmpabs_ui(i.d_value, 2) == 0;
1621 inline friend bool isPositive(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1623 return mpz_sgn(i.d_value) > 0;
1626 inline friend bool isNonNegative(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1628 return mpz_sgn(i.d_value) >= 0;
1631 inline friend bool isNegative(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1633 return mpz_sgn(i.d_value) < 0;
1636 inline friend bool isNonPositive(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1638 return mpz_sgn(i.d_value) <= 0;
1641 inline friend void makeAbs(Integer & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1646 inline friend void euclideanDivision(Integer & q, Integer & r,
const Integer & a,
const Integer & b)
1649 mpz_tdiv_qr(q.d_value, r.d_value, a.d_value, b.d_value);
1655 mpz_fdiv_qr(q.d_value, r.d_value, a.d_value, b.d_value);
1658 inline friend void GCD(Integer & r,
const Integer & x,
const Integer & y)
1661 mpz_gcd(r.d_value, x.d_value, y.d_value);
1664 inline friend void GCD_ui(Integer & r,
const Integer & x,
unsigned long y)
1667 mpz_gcd_ui(r.d_value, x.d_value, y);
1670 inline friend void GCD_si(Integer & r,
const Integer & x,
signed long y)
1673 mpz_gcd_ui(r.d_value, x.d_value, y < 0 ? -y : y);
1676 inline friend void XGCD(Integer & r, Integer & a, Integer & b,
const Integer & x,
const Integer & y)
1679 mpz_gcdext(r.d_value, a.d_value, b.d_value, x.d_value, y.d_value);
1682 inline friend void LCM(Integer & r,
const Integer & x,
const Integer & y)
1685 mpz_lcm(r.d_value, x.d_value, y.d_value);
1688 inline friend void LCM_ui(Integer & r,
const Integer & x,
unsigned long y)
1691 mpz_lcm_ui(r.d_value, x.d_value, y);
1694 inline friend void LCM_si(Integer & r,
const Integer & x,
signed long y)
1697 mpz_lcm_ui(r.d_value, x.d_value, y < 0 ? -y : y);
1700 friend std::ostream &
operator << (std::ostream & s,
const Integer & i);
1703 friend std::istream &
operator >> (std::istream & s, Integer & i);
1709 mpz_set_ui(i.d_value, 0);
1715 mpz_set_ui(i.d_value, 1);
1718 inline friend int compare(
const Integer & a,
const Integer & b)
1721 return mpz_cmp(a.d_value, b.d_value);
1724 inline friend int compare_d(
const Integer & a,
double b)
1727 return mpz_cmp_d(a.d_value, b);
1730 inline friend int compare_ui(
const Integer & a,
unsigned long b)
1733 return mpz_cmp_ui(a.d_value, b);
1736 inline friend int compare_si(
const Integer & a,
signed long b)
1739 return mpz_cmp_si(a.d_value, b);
1746 return mpz_cmpabs(a.d_value, b.d_value);
1749 inline friend int compareAbsValues_d(
const Integer & a,
double b)
1752 return mpz_cmpabs_d(a.d_value, b);
1755 inline friend int compareAbsValues_si(
const Integer & a,
signed long b)
1758 return mpz_cmpabs_ui(a.d_value, b < 0 ? -b : b);
1761 inline friend int compareAbsValues_ui(
const Integer & a,
unsigned long b)
1764 return mpz_cmpabs_ui(a.d_value, b);
1767 inline friend int sign(
const Integer & i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1770 return mpz_sgn(i.d_value);
1773 inline friend int bit(
const Integer & x,
long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1776 return mpz_tstbit(x.d_value, n);
1779 inline friend void setbit(Integer & x,
long n,
bool value)
1783 mpz_setbit(x.d_value, n);
1785 mpz_clrbit(x.d_value, n);
1788 inline friend void square(Integer & r,
const Integer & a)
1790 mpz_mul(r.d_value, a.d_value, a.d_value);
1793 inline friend long approxLog2(
const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1795 return mpz_sizeinbase(x.d_value, 2);
1798 inline friend long ceilOfLog2(
const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1800 mp_bitcnt_t r = mpz_sizeinbase(x.d_value, 2);
1801 mp_bitcnt_t lsb = mpz_scan1(x.d_value, 0);
1802 return (lsb < r - 1) ? r : r - 1;
1805 inline friend long floorOfLog2(
const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1807 return (
long)mpz_sizeinbase(x.d_value, 2) - 1;
1810 inline friend long bitLength(
const Integer & x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1812 return (
long)mpz_sizeinbase(x.d_value, 2);
1817 inline friend
void power(Real & res, const Real & a, const Integer & b);
1820 inline const mpz_t & getInternal() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE {
return d_value; }
1821 inline mpz_t & getInternal() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE {
return d_value; }
1823 inline friend bool operator == (
const Integer & a,
const Integer & b);
1824 inline friend bool operator != (
const Integer & a,
const Integer & b);
1825 inline friend bool operator <= (
const Integer & a,
const Integer & b);
1826 inline friend bool operator >= (
const Integer & a,
const Integer & b);
1827 inline friend bool operator < (
const Integer & a,
const Integer & b);
1828 inline friend bool operator > (
const Integer & a,
const Integer & b);
1832 inline void add_ui(Integer & r,
const Integer & a,
unsigned long b);
1833 inline void add_si(Integer & r,
const Integer & a,
signed long b);
1834 inline void sub_ui(Integer & r,
const Integer & a,
unsigned long b);
1835 inline void sub_si(Integer & r,
const Integer & a,
signed long b);
1836 inline void ui_sub(Integer & r,
unsigned long a,
const Integer & b);
1837 inline void si_sub(Integer & r,
signed long a,
const Integer & b);
1838 inline void mul_ui(Integer & r,
const Integer & a,
unsigned long b);
1839 inline void mul_si(Integer & r,
const Integer & a,
signed long b);
1840 inline void div_ui(Integer & r,
const Integer & a,
unsigned long b);
1841 inline void div_si(Integer & r,
const Integer & a,
signed long b);
1842 inline void mod_ui(Integer & r,
const Integer & a,
unsigned long b);
1843 inline void mod_si(Integer & r,
const Integer & a,
signed long b);
1844 inline void addmul_ui(Integer & r,
const Integer & a,
unsigned long b);
1845 inline void addmul_si(Integer & r,
const Integer & a,
signed long b);
1846 inline void submul_ui(Integer & r,
const Integer & a,
unsigned long b);
1847 inline void submul_si(Integer & r,
const Integer & a,
signed long b);
1848 inline void GCD_ui(Integer & r,
const Integer & x,
unsigned long y);
1849 inline void GCD_si(Integer & r,
const Integer & x,
signed long y);
1850 inline void LCM_ui(Integer & r,
const Integer & x,
unsigned long y);
1851 inline void LCM_si(Integer & r,
const Integer & x,
signed long y);
1852 inline int compare_d(
const Integer & a,
double b);
1853 inline int compare_ui(
const Integer & a,
unsigned long b);
1854 inline int compare_si(
const Integer & a,
signed long b);
1855 inline int compareAbsValues_d(
const Integer & a,
double b);
1856 inline int compareAbsValues_si(
const Integer & a,
signed long b);
1857 inline int compareAbsValues_ui(
const Integer & a,
unsigned long b);
1865 namespace arithmetic
1884 : d_prec(mpfr_get_default_prec()), d_global(
true)
1901 enum { is_cputype =
false, is_realtype =
true, is_inttype =
false, is_exact =
false, is_variable_precision =
true,
1902 has_squareroot =
true, has_full_power =
true, has_special_fns =
true, has_huge_exponent =
true,
1903 has_infinity =
true, has_uniform_rng =
true, has_constants =
true, has_trigonometric =
true };
1909 : d_prec(mpfr_get_default_prec()), d_global(false)
1916 inline explicit RealContext(
long prec) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1917 : d_prec(prec < MPFR_PREC_MIN ? MPFR_PREC_MIN : (prec > MPFR_PREC_MAX ? MPFR_PREC_MAX : prec)), d_global(
false)
1931 if (prec < MPFR_PREC_MIN) prec = MPFR_PREC_MIN;
1932 if (prec > MPFR_PREC_MAX) prec = MPFR_PREC_MAX;
1934 mpfr_set_default_prec(prec);
1944 return d_global ? mpfr_get_default_prec() : d_prec;
1952 return MPFR_PREC_MIN;
1960 return MPFR_PREC_MAX;
2041 #ifndef PLLL_INTERNAL_NO_TEMPLATE_FRIENDS
2042 template<
class X,
class Y>
2055 inline Real(
bool,
unsigned long p)
2057 mpfr_init2(d_value, p);
2060 static void mpfr_set_ll(mpfr_t &,
long long, mpfr_rnd_t);
2061 static long long mpfr_get_ll(
const mpfr_t &, mpfr_rnd_t);
2062 static long long mpfr_get_ll(
const mpfr_t &, mpfr_rnd_t,
bool & roundUp);
2069 unsigned long precision;
2071 inline PrecisionInit(
unsigned long prec) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2079 mpfr_init2(d_value, p.precision);
2101 inline ~Real() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2103 #if __cplusplus >= 201103L
2104 if (d_value[0]._mpfr_d != NULL)
2106 mpfr_clear(d_value);
2109 #if __cplusplus >= 201103L
2115 inline Real(Real && r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2116 : d_value{r.d_value[0]}
2118 r.d_value[0]._mpfr_d = NULL;
2126 inline Real &
operator = (Real && r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2128 mpfr_clear(d_value);
2129 d_value[0] = r.d_value[0];
2130 r.d_value[0]._mpfr_d = NULL;
2140 inline explicit Real(
const RealContext & rc)
2152 inline Real(
const Real & r,
bool clone =
true)
2156 mpfr_init2(d_value, mpfr_get_prec(r.d_value));
2157 mpfr_set(d_value, r.d_value, MPFR_RNDN);
2160 mpfr_init_set(d_value, r.d_value, MPFR_RNDN);
2170 inline explicit Real(
const Real & r,
const RealContext & rc)
2173 mpfr_set(d_value, r.d_value, MPFR_RNDN);
2181 inline unsigned long precision() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2183 return mpfr_get_prec(d_value);
2198 mpfr_set(tmp, d_value, MPFR_RNDN);
2199 mpfr_swap(tmp, d_value);
2211 mpfr_init_set_si(d_value, i, MPFR_RNDN);
2221 inline explicit Real(
long i,
const RealContext & rc)
2224 mpfr_set_si(d_value, i, MPFR_RNDN);
2232 inline explicit Real(
unsigned long i)
2234 mpfr_init_set_ui(d_value, i, MPFR_RNDN);
2244 inline explicit Real(
unsigned long i,
const RealContext & rc)
2247 mpfr_set_ui(d_value, i, MPFR_RNDN);
2258 mpfr_set_ll(d_value, i, MPFR_RNDN);
2268 inline explicit Real(
long long i,
const RealContext & rc)
2271 mpfr_set_ll(d_value, i, MPFR_RNDN);
2282 mpfr_init_set_d(d_value, d, MPFR_RNDN);
2292 inline explicit Real(
double d,
const RealContext & rc)
2295 mpfr_set_d(d_value, d, MPFR_RNDN);
2304 inline explicit Real(
long double d)
2306 mpfr_init_set_ld(d_value, d, MPFR_RNDN);
2316 inline explicit Real(
long double d,
const RealContext & rc)
2319 mpfr_set_ld(d_value, d, MPFR_RNDN);
2328 inline explicit Real(
const Integer & i)
2330 mpfr_init_set_z(d_value, i.d_value, MPFR_RNDN);
2340 inline explicit Real(
const Integer & i,
const RealContext & rc)
2343 mpfr_set_z(d_value, i.d_value, MPFR_RNDN);
2351 template<
class A,
template<
typename,
typename>
class O>
2365 template<
class A,
template<
typename,
typename>
class O>
2380 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2381 if (arithmetic::internal::Real_precision_check_enabled)
2382 assert(mpfr_get_prec(d_value) == mpfr_get_prec(r.d_value));
2384 mpfr_set(d_value, r.d_value, MPFR_RNDN);
2394 template<
class A,
template<
typename,
typename>
class O>
2401 inline friend bool operator == (
const Real & a,
const Real & b);
2402 inline friend bool operator != (
const Real & a,
const Real & b);
2403 inline friend bool operator <= (
const Real & a,
const Real & b);
2404 inline friend bool operator >= (
const Real & a,
const Real & b);
2405 inline friend bool operator < (
const Real & a,
const Real & b);
2406 inline friend bool operator > (
const Real & a,
const Real & b);
2408 inline friend bool isZero(
const Real & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2411 return mpfr_zero_p(r.d_value);
2414 inline friend bool isOne(
const Real & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2417 return mpfr_cmp_ui(r.d_value, 1) == 0;
2420 inline friend bool isPositive(
const Real & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2423 return mpfr_sgn(r.d_value) > 0;
2426 inline friend bool isNonNegative(
const Real & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2429 return mpfr_sgn(r.d_value) >= 0;
2432 inline friend bool isNegative(
const Real & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2435 return mpfr_sgn(r.d_value) < 0;
2438 inline friend bool isNonPositive(
const Real & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2441 return mpfr_sgn(r.d_value) <= 0;
2444 inline friend void add(Real & r,
const Real & a,
const Real & b)
2446 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2447 if (arithmetic::internal::Real_precision_check_enabled)
2449 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2450 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2453 mpfr_add(r.d_value, a.d_value, b.d_value, MPFR_RNDN);
2456 inline friend void add_ui(Real & r,
const Real & a,
unsigned long b)
2459 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2460 if (arithmetic::internal::Real_precision_check_enabled)
2461 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2463 mpfr_add_ui(r.d_value, a.d_value, b, MPFR_RNDN);
2466 inline friend void add_si(Real & r,
const Real & a,
signed long b)
2469 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2470 if (arithmetic::internal::Real_precision_check_enabled)
2471 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2473 mpfr_add_si(r.d_value, a.d_value, b, MPFR_RNDN);
2476 inline friend void add_d(Real & r,
const Real & a,
double b)
2479 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2480 if (arithmetic::internal::Real_precision_check_enabled)
2481 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2483 mpfr_add_d(r.d_value, a.d_value, b, MPFR_RNDN);
2486 inline friend void add_z(Real & r,
const Real & a,
const Integer & b)
2489 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2490 if (arithmetic::internal::Real_precision_check_enabled)
2491 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2493 mpfr_add_z(r.d_value, a.d_value, b.getInternal(), MPFR_RNDN);
2496 inline friend void sub(Real & r,
const Real & a,
const Real & b)
2498 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2499 if (arithmetic::internal::Real_precision_check_enabled)
2501 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2502 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2505 mpfr_sub(r.d_value, a.d_value, b.d_value, MPFR_RNDN);
2508 inline friend void sub_ui(Real & r,
const Real & a,
unsigned long b)
2511 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2512 if (arithmetic::internal::Real_precision_check_enabled)
2513 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2515 mpfr_sub_ui(r.d_value, a.d_value, b, MPFR_RNDN);
2518 inline friend void sub_si(Real & r,
const Real & a,
signed long b)
2521 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2522 if (arithmetic::internal::Real_precision_check_enabled)
2523 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2525 mpfr_sub_si(r.d_value, a.d_value, b, MPFR_RNDN);
2528 inline friend void sub_d(Real & r,
const Real & a,
double b)
2531 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2532 if (arithmetic::internal::Real_precision_check_enabled)
2533 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2535 mpfr_sub_d(r.d_value, a.d_value, b, MPFR_RNDN);
2538 inline friend void sub_z(Real & r,
const Real & a,
const Integer & b)
2541 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2542 if (arithmetic::internal::Real_precision_check_enabled)
2543 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2545 mpfr_sub_z(r.d_value, a.d_value, b.getInternal(), MPFR_RNDN);
2548 inline friend void ui_sub(Real & r,
unsigned long a,
const Real & b)
2551 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2552 if (arithmetic::internal::Real_precision_check_enabled)
2553 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2555 mpfr_ui_sub(r.d_value, a, b.d_value, MPFR_RNDN);
2558 inline friend void si_sub(Real & r,
signed long a,
const Real & b)
2561 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2562 if (arithmetic::internal::Real_precision_check_enabled)
2563 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2565 mpfr_si_sub(r.d_value, a, b.d_value, MPFR_RNDN);
2568 inline friend void d_sub(Real & r,
double a,
const Real & b)
2571 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2572 if (arithmetic::internal::Real_precision_check_enabled)
2573 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2575 mpfr_d_sub(r.d_value, a, b.d_value, MPFR_RNDN);
2578 inline friend void z_sub(Real & r,
const Integer & a,
const Real & b)
2581 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2582 if (arithmetic::internal::Real_precision_check_enabled)
2583 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2585 mpfr_z_sub(r.d_value, a.getInternal(), b.d_value, MPFR_RNDN);
2588 inline friend void addmul(Real & r,
const Real & a,
const Real & b)
2590 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2591 if (arithmetic::internal::Real_precision_check_enabled)
2593 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2594 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2597 mpfr_fma(r.d_value, a.d_value, b.d_value, r.d_value, MPFR_RNDN);
2600 inline friend void addmul4(Real & r,
const Real & a,
const Real & b,
const Real & c)
2603 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2604 if (arithmetic::internal::Real_precision_check_enabled)
2606 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2607 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2608 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(c.d_value));
2611 mpfr_fma(r.d_value, a.d_value, b.d_value, c.d_value, MPFR_RNDN);
2614 inline friend void submul(Real & r,
const Real & a,
const Real & b)
2616 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2617 if (arithmetic::internal::Real_precision_check_enabled)
2619 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2620 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2623 mpfr_fms(r.d_value, a.d_value, b.d_value, r.d_value, MPFR_RNDN);
2624 mpfr_neg(r.d_value, r.d_value, MPFR_RNDN);
2627 inline friend void submul4(Real & r,
const Real & a,
const Real & b,
const Real & c)
2630 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2631 if (arithmetic::internal::Real_precision_check_enabled)
2633 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2634 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2635 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(c.d_value));
2638 mpfr_fms(r.d_value, a.d_value, b.d_value, c.d_value, MPFR_RNDN);
2641 inline friend void mul(Real & r,
const Real & a,
const Real & b)
2643 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2644 if (arithmetic::internal::Real_precision_check_enabled)
2646 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2647 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2650 mpfr_mul(r.d_value, a.d_value, b.d_value, MPFR_RNDN);
2653 inline friend void mul_ui(Real & r,
const Real & a,
unsigned long b)
2656 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2657 if (arithmetic::internal::Real_precision_check_enabled)
2658 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2660 mpfr_mul_ui(r.d_value, a.d_value, b, MPFR_RNDN);
2663 inline friend void mul_si(Real & r,
const Real & a,
signed long b)
2666 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2667 if (arithmetic::internal::Real_precision_check_enabled)
2668 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2670 mpfr_mul_si(r.d_value, a.d_value, b, MPFR_RNDN);
2673 inline friend void mul_d(Real & r,
const Real & a,
double b)
2676 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2677 if (arithmetic::internal::Real_precision_check_enabled)
2678 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2680 mpfr_mul_d(r.d_value, a.d_value, b, MPFR_RNDN);
2683 inline friend void mul_z(Real & r,
const Real & a,
const Integer & b)
2686 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2687 if (arithmetic::internal::Real_precision_check_enabled)
2688 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2690 mpfr_mul_z(r.d_value, a.d_value, b.getInternal(), MPFR_RNDN);
2693 inline friend void div(Real & r,
const Real & a,
const Real & b)
2695 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2696 if (arithmetic::internal::Real_precision_check_enabled)
2698 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2699 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2702 mpfr_div(r.d_value, a.d_value, b.d_value, MPFR_RNDN);
2705 inline friend void div_ui(Real & r,
const Real & a,
unsigned long b)
2708 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2709 if (arithmetic::internal::Real_precision_check_enabled)
2710 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2712 mpfr_div_ui(r.d_value, a.d_value, b, MPFR_RNDN);
2715 inline friend void div_si(Real & r,
const Real & a,
signed long b)
2718 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2719 if (arithmetic::internal::Real_precision_check_enabled)
2720 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2722 mpfr_div_si(r.d_value, a.d_value, b, MPFR_RNDN);
2725 inline friend void div_d(Real & r,
const Real & a,
double b)
2728 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2729 if (arithmetic::internal::Real_precision_check_enabled)
2730 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2732 mpfr_div_d(r.d_value, a.d_value, b, MPFR_RNDN);
2735 inline friend void div_z(Real & r,
const Real & a,
const Integer & b)
2738 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2739 if (arithmetic::internal::Real_precision_check_enabled)
2740 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2742 mpfr_div_z(r.d_value, a.d_value, b.getInternal(), MPFR_RNDN);
2745 inline friend void ui_div(Real & r,
unsigned long a,
const Real & b)
2748 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2749 if (arithmetic::internal::Real_precision_check_enabled)
2750 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2752 mpfr_ui_div(r.d_value, a, b.d_value, MPFR_RNDN);
2755 inline friend void si_div(Real & r,
signed long a,
const Real & b)
2758 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2759 if (arithmetic::internal::Real_precision_check_enabled)
2760 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2762 mpfr_si_div(r.d_value, a, b.d_value, MPFR_RNDN);
2765 inline friend void d_div(Real & r,
double a,
const Real & b)
2768 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2769 if (arithmetic::internal::Real_precision_check_enabled)
2770 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2772 mpfr_d_div(r.d_value, a, b.d_value, MPFR_RNDN);
2775 inline friend void mod(Real & r,
const Real & a,
const Real & b)
2777 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2778 if (arithmetic::internal::Real_precision_check_enabled)
2780 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2781 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2784 mpfr_fmod(r.d_value, a.d_value, b.d_value, MPFR_RNDN);
2787 inline friend void divmod(Real & q, Real & r,
const Real & a,
const Real & b)
2789 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2790 if (arithmetic::internal::Real_precision_check_enabled)
2792 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2793 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2794 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(q.d_value));
2797 if ((&r == &a) || (&r == &b))
2799 if ((&q == &a) || (&q == &b) || (mpfr_get_prec(q.d_value) != mpfr_get_prec(r.d_value)))
2802 mpfr_init2(tmp, mpfr_get_prec(r.d_value));
2803 mpfr_fmod(tmp, a.d_value, b.d_value, MPFR_RNDN);
2804 mpfr_fms(q.d_value, tmp, b.d_value, a.d_value, MPFR_RNDN);
2805 mpfr_neg(q.d_value, q.d_value, MPFR_RNDN);
2806 mpfr_swap(r.d_value, tmp);
2811 mpfr_fmod(q.d_value, a.d_value, b.d_value, MPFR_RNDN);
2812 mpfr_fms(r.d_value, q.d_value, b.d_value, a.d_value, MPFR_RNDN);
2813 mpfr_neg(r.d_value, r.d_value, MPFR_RNDN);
2814 mpfr_swap(q.d_value, r.d_value);
2819 mpfr_fmod(r.d_value, a.d_value, b.d_value, MPFR_RNDN);
2820 mpfr_fms(q.d_value, r.d_value, b.d_value, a.d_value, MPFR_RNDN);
2821 mpfr_neg(q.d_value, q.d_value, MPFR_RNDN);
2825 inline friend void shl(Real & r,
const Real & a,
const Real & b)
2827 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2828 if (arithmetic::internal::Real_precision_check_enabled)
2830 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2831 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2835 mpfr_init2(tmp, mpfr_get_prec(r.d_value));
2836 mpfr_ui_pow(tmp, 2, b.d_value, MPFR_RNDN);
2837 mpfr_mul(r.d_value, a.d_value, tmp, MPFR_RNDN);
2841 inline friend void shr(Real & r,
const Real & a,
const Real & b)
2843 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2844 if (arithmetic::internal::Real_precision_check_enabled)
2846 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2847 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(b.d_value));
2851 mpfr_init2(tmp, mpfr_get_prec(r.d_value));
2852 mpfr_ui_pow(tmp, 2, b.d_value, MPFR_RNDN);
2853 mpfr_div(r.d_value, a.d_value, tmp, MPFR_RNDN);
2857 inline friend void shl(Real & r,
const Real & a,
long b)
2859 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2860 if (arithmetic::internal::Real_precision_check_enabled)
2861 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2863 mpfr_mul_2si(r.d_value, a.d_value, b, MPFR_RNDN);
2866 inline friend void shr(Real & r,
const Real & a,
long b)
2868 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2869 if (arithmetic::internal::Real_precision_check_enabled)
2870 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2872 mpfr_div_2si(r.d_value, a.d_value, b, MPFR_RNDN);
2877 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2878 if (arithmetic::internal::Real_precision_check_enabled)
2879 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2881 mpfr_add_ui(r.d_value, a.d_value, 1, MPFR_RNDN);
2886 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2887 if (arithmetic::internal::Real_precision_check_enabled)
2888 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2890 mpfr_sub_ui(r.d_value, a.d_value, 1, MPFR_RNDN);
2893 inline friend void neg(Real & r,
const Real & a)
2895 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2896 if (arithmetic::internal::Real_precision_check_enabled)
2897 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2899 mpfr_neg(r.d_value, a.d_value, MPFR_RNDN);
2902 inline friend void abs(Real & r,
const Real & a)
2904 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2905 if (arithmetic::internal::Real_precision_check_enabled)
2906 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
2908 mpfr_abs(r.d_value, a.d_value, MPFR_RNDN);
2911 inline friend void makeAbs(Real & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
2916 friend std::ostream &
operator << (std::ostream & s,
const Real & r);
2919 friend std::istream &
operator >> (std::istream & s, Real & r);
2924 mpfr_set_nan(r.d_value);
2929 mpfr_set_inf(r.d_value, sign ? 1 : -1);
2935 #if (MPFR_VERSION <= 0x0204FF)
2936 mpfr_set_ui(r.d_value, 0, MPFR_RNDN);
2938 mpfr_neg(r.d_value, r.d_value, MPFR_RNDN);
2940 mpfr_set_zero(r.d_value, sign ? 1 : -1);
2947 mpfr_set_ui(r.d_value, 1, MPFR_RNDN);
2950 inline friend int compare(
const Real & a,
const Real & b)
2953 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
2954 if (arithmetic::internal::Real_precision_check_enabled)
2955 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(b.d_value));
2957 return mpfr_cmp(a.d_value, b.d_value);
2960 inline friend int compare_ui(
const Real & a,
unsigned long b)
2963 return mpfr_cmp_ui(a.d_value, b);
2966 inline friend int compare_si(
const Real & a,
signed long b)
2969 return mpfr_cmp_si(a.d_value, b);
2972 inline friend int compare_d(
const Real & a,
double b)
2975 return mpfr_cmp_d(a.d_value, b);
2978 inline friend int compare_ld(
const Real & a,
long double b)
2981 return mpfr_cmp_ld(a.d_value, b);
2984 inline friend int compare_z(
const Real & a,
const Integer & b)
2987 return mpfr_cmp_z(a.d_value, b.getInternal());
2990 inline friend int compare_ui2(
const Real & a,
unsigned long b,
long exp)
2993 return mpfr_cmp_ui_2exp(a.d_value, b, exp);
2996 inline friend int compare_si2(
const Real & a,
signed long b,
long exp)
2999 return mpfr_cmp_si_2exp(a.d_value, b, exp);
3006 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3007 if (arithmetic::internal::Real_precision_check_enabled)
3008 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(b.d_value));
3010 return mpfr_cmpabs(a.d_value, b.d_value);
3013 inline friend int sign(
const Real & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3016 return mpfr_sgn(r.d_value);
3019 inline friend void square(Real & r,
const Real & a)
3021 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3022 if (arithmetic::internal::Real_precision_check_enabled)
3023 assert(mpfr_get_prec(r.d_value) == mpfr_get_prec(a.d_value));
3025 mpfr_sqr(r.d_value, a.d_value, MPFR_RNDN);
3028 inline friend void sin(Real & res,
const Real & a)
3030 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3031 if (arithmetic::internal::Real_precision_check_enabled)
3032 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3034 mpfr_sin(res.d_value, a.d_value, MPFR_RNDN);
3037 inline friend void cos(Real & res,
const Real & a)
3039 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3040 if (arithmetic::internal::Real_precision_check_enabled)
3041 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3043 mpfr_cos(res.d_value, a.d_value, MPFR_RNDN);
3046 inline friend void tan(Real & res,
const Real & a)
3048 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3049 if (arithmetic::internal::Real_precision_check_enabled)
3050 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3052 mpfr_tan(res.d_value, a.d_value, MPFR_RNDN);
3055 inline friend void asin(Real & res,
const Real & a)
3057 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3058 if (arithmetic::internal::Real_precision_check_enabled)
3059 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3061 mpfr_asin(res.d_value, a.d_value, MPFR_RNDN);
3064 inline friend void acos(Real & res,
const Real & a)
3066 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3067 if (arithmetic::internal::Real_precision_check_enabled)
3068 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3070 mpfr_acos(res.d_value, a.d_value, MPFR_RNDN);
3073 inline friend void atan(Real & res,
const Real & a)
3075 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3076 if (arithmetic::internal::Real_precision_check_enabled)
3077 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3079 mpfr_atan(res.d_value, a.d_value, MPFR_RNDN);
3082 inline friend void atan2(Real & res,
const Real & y,
const Real & x)
3084 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3085 if (arithmetic::internal::Real_precision_check_enabled)
3087 assert(mpfr_get_prec(y.d_value) == mpfr_get_prec(res.d_value));
3088 assert(mpfr_get_prec(x.d_value) == mpfr_get_prec(res.d_value));
3091 mpfr_atan2(res.d_value, y.d_value, x.d_value, MPFR_RNDN);
3094 inline friend void exp(Real & res,
const Real & a)
3096 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3097 if (arithmetic::internal::Real_precision_check_enabled)
3098 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3100 mpfr_exp(res.d_value, a.d_value, MPFR_RNDN);
3103 inline friend void log(Real & res,
const Real & a)
3105 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3106 if (arithmetic::internal::Real_precision_check_enabled)
3107 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3109 mpfr_log(res.d_value, a.d_value, MPFR_RNDN);
3112 inline friend void log2(Real & res,
const Real & a)
3114 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3115 if (arithmetic::internal::Real_precision_check_enabled)
3116 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3118 mpfr_log2(res.d_value, a.d_value, MPFR_RNDN);
3121 inline friend void log10(Real & res,
const Real & a)
3123 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3124 if (arithmetic::internal::Real_precision_check_enabled)
3125 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3127 mpfr_log10(res.d_value, a.d_value, MPFR_RNDN);
3130 inline friend void sqrt(Real & res,
const Real & a)
3132 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3133 if (arithmetic::internal::Real_precision_check_enabled)
3134 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3136 mpfr_sqrt(res.d_value, a.d_value, MPFR_RNDN);
3139 inline friend void gamma(Real & res,
const Real & a)
3141 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3142 if (arithmetic::internal::Real_precision_check_enabled)
3143 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3145 mpfr_gamma(res.d_value, a.d_value, MPFR_RNDN);
3148 inline friend void lgamma(Real & res,
const Real & a)
3150 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3151 if (arithmetic::internal::Real_precision_check_enabled)
3152 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3155 mpfr_lgamma(res.d_value, &sign, a.d_value, MPFR_RNDN);
3158 inline friend void lgamma(Real & res,
int &
sign,
const Real & a)
3160 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3161 if (arithmetic::internal::Real_precision_check_enabled)
3162 assert(mpfr_get_prec(a.d_value) == mpfr_get_prec(res.d_value));
3164 mpfr_lgamma(res.d_value, &sign, a.d_value, MPFR_RNDN);
3167 inline friend void power(Real & res,
const Real & a,
signed long b)
3169 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3170 if (arithmetic::internal::Real_precision_check_enabled)
3171 assert(mpfr_get_prec(res.d_value) == mpfr_get_prec(a.d_value));
3173 mpfr_pow_si(res.d_value, a.d_value, b, MPFR_RNDN);
3176 inline friend void power(Real & res,
const Real & a,
unsigned long b)
3178 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3179 if (arithmetic::internal::Real_precision_check_enabled)
3180 assert(mpfr_get_prec(res.d_value) == mpfr_get_prec(a.d_value));
3182 mpfr_pow_ui(res.d_value, a.d_value, b, MPFR_RNDN);
3185 inline friend void power(Real & res,
const Real & a,
const Integer & b)
3187 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3188 if (arithmetic::internal::Real_precision_check_enabled)
3189 assert(mpfr_get_prec(res.d_value) == mpfr_get_prec(a.d_value));
3191 mpfr_pow_z(res.d_value, a.d_value, b.d_value, MPFR_RNDN);
3194 inline friend void power(Real & res,
const Real & a,
const Real & b)
3196 #ifdef PLLL_INTERNAL__BIGINT__HELP_FINDING_PRECISION_BUGS
3197 if (arithmetic::internal::Real_precision_check_enabled)
3199 assert(mpfr_get_prec(res.d_value) == mpfr_get_prec(a.d_value));
3200 assert(mpfr_get_prec(res.d_value) == mpfr_get_prec(b.d_value));
3203 mpfr_pow(res.d_value, a.d_value, b.d_value, MPFR_RNDN);
3217 return (mpfr_zero_p(d_value) != 0) ? std::numeric_limits<long>::min() : mpfr_get_exp(d_value);
3221 const mpfr_t & getInternal() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE {
return d_value; }
3222 mpfr_t & getInternal() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE {
return d_value; }
3225 inline void swap(Integer & a, Integer & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3227 mpz_swap(a.d_value, b.d_value);
3231 inline void add_ui(Real & r,
const Real & a,
unsigned long b);
3232 inline void add_si(Real & r,
const Real & a,
signed long b);
3233 inline void add_d(Real & r,
const Real & a,
double b);
3234 inline void add_z(Real & r,
const Real & a,
const Integer & b);
3235 inline void sub_ui(Real & r,
const Real & a,
unsigned long b);
3236 inline void sub_si(Real & r,
const Real & a,
signed long b);
3237 inline void sub_d(Real & r,
const Real & a,
double b);
3238 inline void sub_z(Real & r,
const Real & a,
const Integer & b);
3239 inline void ui_sub(Real & r,
unsigned long a,
const Real & b);
3240 inline void si_sub(Real & r,
signed long a,
const Real & b);
3241 inline void d_sub(Real & r,
double a,
const Real & b);
3242 inline void z_sub(Real & r,
const Integer & a,
const Real & b);
3243 inline void addmul4(Real & r,
const Real & a,
const Real & b,
const Real & c);
3244 inline void submul4(Real & r,
const Real & a,
const Real & b,
const Real & c);
3245 inline void mul_ui(Real & r,
const Real & a,
unsigned long b);
3246 inline void mul_si(Real & r,
const Real & a,
signed long b);
3247 inline void mul_d(Real & r,
const Real & a,
double b);
3248 inline void mul_z(Real & r,
const Real & a,
const Integer & b);
3249 inline void div_ui(Real & r,
const Real & a,
unsigned long b);
3250 inline void div_si(Real & r,
const Real & a,
signed long b);
3251 inline void div_d(Real & r,
const Real & a,
double b);
3252 inline void div_z(Real & r,
const Real & a,
const Integer & b);
3253 inline void ui_div(Real & r,
unsigned long a,
const Real & b);
3254 inline void si_div(Real & r,
signed long a,
const Real & b);
3255 inline void d_div(Real & r,
double a,
const Real & b);
3256 inline int compare_ui(
const Real & a,
unsigned long b);
3257 inline int compare_si(
const Real & a,
signed long b);
3258 inline int compare_d(
const Real & a,
double b);
3259 inline int compare_ld(
const Real & a,
long double b);
3260 inline int compare_z(
const Real & a,
const Integer & b);
3261 inline int compare_ui2(
const Real & a,
unsigned long b,
long exp);
3262 inline int compare_si2(
const Real & a,
signed long b,
long exp);
3270 namespace arithmetic
3327 void setSeed(
const Integer & seed);
3395 void random(Integer & res,
const Integer & bound);
3403 Integer
random(
const Integer & bound);
3411 unsigned long random(
unsigned long bound);
3419 void randomBits(
void * ptr,
unsigned long count);
3427 void randomBits(Integer & res,
unsigned long bits);
3443 void randomLen(Integer & res,
unsigned long bits);
3550 mpfr_clear(x.d_value);
3565 mpfr_const_pi(x.d_value, MPFR_RNDN);
3577 mpfr_const_euler(x.d_value, MPFR_RNDN);
3589 mpfr_const_log2(x.d_value, MPFR_RNDN);
3613 inline void random(Integer & res,
const Integer & bound)
3615 d_rng.
random(res, bound);
3625 inline Integer
random(
const Integer & bound,
const IntegerContext & ic)
3650 inline Integer
randomBits(
unsigned long bits,
const IntegerContext & ic)
3675 inline Integer
randomLen(
unsigned long bits,
const IntegerContext & ic)
3683 inline void swap(Real & a, Real & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
3685 mpfr_swap(a.d_value, b.d_value);
friend bool isNonPositive(const Real &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Real object for being negative or zero.
void randomLen(Integer &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 .
friend bool operator>(const Integer &a, const Integer &b)
Compares the current integer with the given one.
friend void mul(Real &r, const Real &a, const Real &b)
Multiplies a with b and stores the result in r.
void submul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and subtracts the result from r.
Real(long long i, const RealContext &rc)
Creates a new floating point number from the given native integer with the given context's precision...
Real randomUniform(const RealContext &rc)
Creates and returns a uniformly distributed floating point number in the interval ...
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.
friend void makeAbs(Real &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Makes the operand non-negative.
friend void sub(Real &r, const Real &a, const Real &b)
Subtracts b from a and stores the result in r.
RealContext & getThreadRealContext()
Retrieves a context for the current thread. The context is thread local and cannot be accessed by thi...
friend void div(Integer &r, const Integer &a, const Integer &b)
Divides a by b and stores the result in r.
Real(const Real &r, bool clone=true)
Creates a copy of the given floating point number.
Real(long long i)
Creates a new floating point number from the given native integer.
Real(unsigned long i, const RealContext &rc)
Creates a new floating point number from the given native integer with the given context's precision...
bool isZero(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being zero.
friend void setbit(Integer &x, long n, bool value)
Sets the n-th bit of to value.
friend bool isPMTwo(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being two or minus two.
Real(long double d, const RealContext &rc)
Creates a new floating point number from the given native floating point number with the given contex...
Real(long i)
Creates a new floating point number from the given native integer.
friend bool isZero(const Real &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Real object for being zero.
friend void submul(Real &r, const Real &a, const Real &b)
Multiplies a and b and subtracts the result from r.
void initArithmeticThreadAllocators()
Initializes the local thread allocator for the current thread, and sets the GMP and MPFR allocators t...
Integer(signed long i)
Creates a arbitrary precision integer from the given native integer.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ATanOp > atan(const Real &i)
Returns the arctangent of the given floating point number.
void randomUniform(Real &r)
Creates a uniformly distributed floating point number in the interval .
friend void setInfinity(Real &r, bool sign)
Sets the given floating point number to .
bool isPMTwo(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being two or minus two.
friend bool isNegative(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being strictly negative.
Real(double d)
Creates a new floating point number from the given native floating point number.
void randomizeTime()
Uses the system's time to seed this random number generator.
friend bool isNegative(const Real &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Real object for being strictly negative.
friend void shr(Real &r, const Real &a, const Real &b)
Multiplies a by and stores the result in r.
friend bool operator<(const Integer &a, const Integer &b)
Compares the current integer with the given one.
friend bool operator<=(const Integer &a, const Integer &b)
Compares the current integer with the given one.
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.
friend bool isPositive(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being strictly positive.
bool isNegative(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being strictly negative.
friend void sub(Integer &r, const Integer &a, const Integer &b)
Subtracts b from a and stores the result in r.
friend bool operator!=(const Real &a, const Real &b)
Compares the two floating point numbers a and b for inequality.
friend bool isNonNegative(const Real &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Real object for being positive or zero.
Real(long i, const RealContext &rc)
Creates a new floating point number from the given native integer with the given context's precision...
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.
static Integer createSeed()
Creates a seed using an internal random number generator.
friend void abs(Real &r, const Real &a)
Takes the absolute value of a and stores the result in r.
RandomNumberGenerator & operator=(const RandomNumberGenerator &rng)
Copies the state of the given random number generator to the current one.
void bneg(Integer &r, const Integer &a)
Takes the bitwise complement of a and stores the result in r.
Integer & operator=(const Integer &i)
Assigns the integer i to the current integer.
friend bool operator>=(const Real &a, const Real &b)
Compares the two floating point numbers a and b.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SqrtFloorOp > sqrtFloor(const Integer &i)
Computes and returns the floor of the square root of i.
static unsigned long getMinRealPrecision() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the minimal possible precision for this context.
friend long floorOfLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns .
Conversion definitions for integers and floating point numbers.
bool isOne(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being one.
friend void setOne(Real &r)
Sets the given floating point number to one.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::TanOp > tan(const Real &i)
Returns the tangent of the given floating point number.
friend void floorDiv(Integer &r, const Integer &a, const Integer &b)
Computes and stores the result in r.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::GammaOp > gamma(const Real &i)
Returns the Gamma function evaluated at the given floating point number.
friend void cos(Real &res, const Real &a)
Computes the cosine of a and stores the result in res.
Integer(unsigned int i)
Creates a arbitrary precision integer from the given native integer.
Integer random(const Integer &bound, const IntegerContext &ic)
Creates and returns a random arbitrary precision integer in the range .
Operator definitions for floating point numbers.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::AbsOp > abs(const Integer &i)
Computes and returns the absolute value of i.
friend void shl(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
RealContext(long prec) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new real context with the given precision.
Operator definitions for integers.
Real(const Integer &i, const RealContext &rc)
Creates a new floating point number from the given arbitrary precision integer with the given context...
static unsigned long getMaxRealPrecision() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the maximal possible precision for this context.
friend void bxor(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise exclusive or of a and b and stores the result in r.
friend void log(Real &res, const Real &a)
Computes the natural logarithm of a and stores the result in res.
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.
RandomNumberGenerator()
Creates a new default initialized random number generator.
void randomBits(Integer &res, unsigned long bits)
Creates random bits.
friend void setNaN(Real &r)
Sets the given floating point number to Not a Number.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::CeilDivOp > ceilDiv(const Integer &a, const Integer &b)
Computes and returns .
friend void increment(Integer &r, const Integer &a)
Increments a by one and stores the result in r.
friend void decrement(Integer &r, const Integer &a)
Decrements a by one and stores the result in r.
unsigned long precision() const
Returns the precision of the expression. Only compiles if the expression supports this...
friend bool operator!=(const Integer &a, const Integer &b)
Compares the current integer with the given one for inequality.
long approxLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Quickly approximates and returns the approximation.
void random(Integer &res, const Integer &bound)
Creates a random arbitrary precision integer in the range .
friend void roundDiv(Integer &r, const Integer &a, const Integer &b)
Computes (rounding to the next integer) and stores the result in r.
friend void acos(Real &res, const Real &a)
Computes the arccosine of a and stores the result in res.
Real & operator=(const Real &r)
Assigns the given floating point number r to this floating point number.
expressions::Expression< RealContext, std::pair< expressions::Wrapper< RealContext >, expressions::Wrapper< RealContext > >, expressions::ATan2Op > atan2(const Real &y, const Real &x)
Returns the arctangent of , using the signs of x and y to determine the quadrant. ...
Real randomUniform()
Creates and returns a uniformly distributed floating point number in the interval ...
friend void mod(Real &r, const Real &a, const Real &b)
Takes the remainder of the division of a by b and stores it in r.
void randomUniform(Real &r)
Creates a uniformly distributed floating point number in the interval .
friend void abs(Integer &r, const Integer &a)
Takes the absolute value of a and stores the result in r.
arithmetic::Real Real
The floating point type.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::Log2Op > log2(const Real &i)
Returns the base-2 logarithm evaluated at the given floating point number.
friend void euclideanDivision(Integer &q, Integer &r, const Integer &a, const Integer &b)
Computes an Euclidean Division of a by b.
friend int compareAbsValues(const Real &a, const Real &b)
Compares the two floating point numbers in absolute value.
Integer(unsigned long i)
Creates a arbitrary precision integer from the given native integer.
friend void shl(Real &r, const Real &a, const Real &b)
Multiplies a by and stores the result in r.
void setZero(Integer &)
Sets the given integer to zero.
void setContext(const RealContext &rc)
Adjusts the precision of this floating point number to the given context's precision.
void setRealPrecision(unsigned long prec) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Sets the precision of this context.
Integer(const expressions::Expression< IntegerContext, A, O > &E, const IntegerContext &ic)
Creates an integer from the given integer expression.
friend bool operator==(const Integer &a, const Integer &b)
Compares the current integer with the given one for equality.
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.
friend void log10(Real &res, const Real &a)
Computes the logarithm of a to base 10 and stores the result in res.
friend 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 setNaN(Real &)
Sets the given floating point number to Not a Number.
Real(const RealContext &rc)
Creates a real with the precision given by the context.
friend void ceilDiv(Integer &r, const Integer &a, const Integer &b)
Computes and stores the result in r.
static void setContext(const IntegerContext &c)
Sets the integer context c.
friend std::istream & operator>>(std::istream &s, Integer &i)
Reads the integer from the given input stream.
friend void neg(Real &r, const Real &a)
Negates a and stores the result in r.
Real(unsigned long i)
Creates a new floating point number from the given native integer.
friend bool isNonNegative(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being positive or zero.
Provides facilities to convert strings to types.
Real getPi() const
Returns an approximation of for the current context.
friend void sin(Real &res, const Real &a)
Computes the sine of a and stores the result in res.
long getApproxExponent() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns approximate e such that |x| is approximately .
Integer randomBits(unsigned long bits, const IntegerContext &ic)
Creates random bits.
Real(const expressions::Expression< RealContext, A, O > &E, const RealContext &rc)
Creates a floating point number from the given floating point expression and Real context...
friend bool isOne(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being one.
friend bool operator>=(const Integer &a, const Integer &b)
Compares the current integer with the given one.
friend void bor(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise or of a and b and stores the result in r.
friend void atan(Real &res, const Real &a)
Computes the arctangent of a and stores the result in res.
friend std::ostream & operator<<(std::ostream &s, const Integer &i)
Outputs the integer on the given output stream.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::LogOp > log(const Real &i)
Returns the natural logarithm evaluated at the given floating point number.
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.
friend std::istream & operator>>(std::istream &s, Real &r)
Reads the floating point number from the given input stream.
static void initializeSeeder(double goodness=0.01)
Calls randomizeDevRandom(goodness) for the internal random number generator which is used for createS...
void setSeed(const Integer &seed)
Sets a new seed for the generator.
Real(const expressions::Expression< RealContext, A, O > &E)
Creates a floating point number from the given floating point expression.
friend void square(Real &r, const Real &a)
Computes the square of a and stores the result in r.
friend void add(Real &r, const Real &a, const Real &b)
Adds a and b and stores the result in r.
Provides facilities to convert types to std::strings.
friend 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.
friend void gamma(Real &res, const Real &a)
Computes the Gamma function at a and stores the result in res.
friend void bneg(Integer &r, const Integer &a)
Takes the bitwise complement of a and stores the result in r.
friend bool operator==(const Real &a, const Real &b)
Compares the two floating point numbers a and b for equality.
Integer(const Integer &i)
Creates a copy of the given integer.
friend void neg(Integer &r, const Integer &a)
Negates a and stores the result in r.
void random(Integer &res, const Integer &bound)
Creates a random arbitrary precision integer in the range .
~Real() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory used by the arbitrary precision floating point number.
friend int compare(const Real &a, const Real &b)
Compares the two floating point numbers.
friend void tan(Real &res, const Real &a)
Computes the tangent of a and stores the result in res.
Real(double d, const RealContext &rc)
Creates a new floating point number from the given native floating point number with the given contex...
friend void euclideanDivisionPos(Integer &q, Integer &r, const Integer &a, const Integer &b)
Computes an Euclidean Division of a by b.
friend void setZero(Real &r, bool sign)
Sets the given floating point number to .
unsigned long precision() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Retrieves the precision of this floating point number.
RealContext Context
The context type.
Implementation backend for conversions from context types to native types.
Integer(signed int i)
Creates a arbitrary precision integer from the given native integer.
friend void div(Real &r, const Real &a, const Real &b)
Divides a by b and stores the result in r.
~Integer() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Releases the memory used by the arbitrary precision integer.
friend bool isOne(const Real &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Real object for being one.
arithmetic::Integer Type
The integer type.
Represents a random number generator.
friend long bitLength(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns n such that .
friend void submul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and subtracts the result from r.
void swap(plll::arithmetic::Integer &, plll::arithmetic::Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Swaps two plll::arithmetic::Integer objects.
void bor(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise or of a and b and stores the result in r.
friend void power(Integer &r, const Integer &a, long b)
Raises a to the power b and stores the result in r.
friend int bit(const Integer &x, long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the n bit of in the usual binary representation.
friend void band(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise and of a and b and stores the result in r.
friend void sqrtCeil(Integer &r, const Integer &a)
Computes and stores the result in r.
~RandomNumberGenerator()
Releases the state for this random number generator.
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.
void randomLen(Integer &res, unsigned long bits)
Creates a random integer of a fixed bit length.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SqrtCeilOp > sqrtCeil(const Integer &i)
Computes and returns the ceil of the square root of i.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::SinOp > sin(const Real &i)
Returns the sine of the given floating point number.
friend void atan2(Real &res, const Real &y, const Real &x)
Computes the arctangent of and stores the result inres. The signs ofxandy` are used to determine the ...
friend void makeAbs(Integer &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Makes the operand non-negative.
Integer(long long i)
Creates a arbitrary precision integer from the given native integer.
void setbit(Integer &x, long n, bool value=true)
Sets the n-th bit of to value.
friend void sqrtFloor(Integer &r, const Integer &a)
Computes and stores the result in r.
friend bool operator>(const Real &a, const Real &b)
Compares the two floating point numbers a and b.
void bxor(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise exclusive or of a and b and stores the result in r.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ASinOp > asin(const Real &i)
Returns the arcsine of the given floating point number.
Real(const Integer &i)
Creates a new floating point number from the given arbitrary precision integer.
friend void square(Integer &r, const Integer &a)
Computes the square of a and stores the result in r.
Real getEpsilon() const
Returns the machine constant for the current context.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::Log10Op > log10(const Real &i)
Returns the base-10 logarithm evaluated at the given floating point number.
friend int compare(const Integer &a, const Integer &b)
Compares the two integers.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ACosOp > acos(const Real &i)
Returns the arccosine of the given floating point number.
Represents an expression.
int compareAbsValues(const Integer &a, const Integer &b)
Compares the two integers in absolute value.
friend void setOne(Integer &i)
Sets the given integer to one.
friend void add(Integer &r, const Integer &a, const Integer &b)
Adds a and b and stores the result in r.
Represents an arbitrary precision floating point value.
Integer()
Creates a new integer. Default value is zero.
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 .
Integer getSeed() const
Retrieves the last set seed of the generator.
Integer(const IntegerContext &c)
Creates a new integer. Default value is zero.
friend RealContext & getThreadRealContext()
Retrieves a context for the current thread. The context is thread local and cannot be accessed by thi...
friend bool operator<(const Real &a, const Real &b)
Compares the two floating point numbers a and b.
int sign(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the sign of the given integer.
RealContext() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new real context with the current global default precision.
Real(const Real &r, const RealContext &rc)
Creates a copy of the given floating point number with the given context's precision.
friend 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.
friend std::ostream & operator<<(std::ostream &s, const Real &r)
Outputs the floating point number on the given output stream.
void shl(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
UniformRNG(RandomNumberGenerator &rng) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new uniform random number generator based on the given random number generator.
void band(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise and of a and b and stores the result in r.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::CosOp > cos(const Real &i)
Returns the cosine of the given floating point number.
friend void increment(Real &r, const Real &a)
Increments a by one and stores the result in r.
arithmetic::Integer Integer
The integer type.
Represents an arithmetic context for arbitrary precision floating point values.
friend bool isPMOne(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being one or minus one.
void neg(Integer &r, const Integer &a)
Negates a and stores the result in r.
friend void exp(Real &res, const Real &a)
Computes the exponential function at a and stores the result in res.
friend void divmod(Real &q, Real &r, const Real &a, const Real &b)
Stores quotient and remainder of the division of a by b in q respectively r.
void addmul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and adds the result to r.
friend void lgamma(Real &res, const Real &a)
Computes the logarithm of the absolute value of the Gamma function at a and stores the result in res...
bool isPositive(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being strictly positive.
friend void setZero(Integer &i)
Sets the given integer to zero.
Integer(double d)
Creates a arbitrary precision integer from the given native floating point number.
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.
Integer(const Integer &i, const IntegerContext &ic)
Creates a copy of the given integer.
void add(Integer &r, const Integer &a, const Integer &b)
Adds a and b and stores the result in r.
arithmetic::Real Type
The floating point type.
Real getLog2() const
Returns an approximation of the natural logarithm for the current context.
friend void LCM(Integer &r, const Integer &x, const Integer &y)
Computes the non-negative Least Common Multiple r of x and y.
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 .
friend int sign(const Real &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the sign of the given floating point number.
friend void addmul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and adds the result to r.
void randomizeDevRandom(double goodness=0.01)
Uses the operating system's random number generator to initialize this random number generator...
long floorOfLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns .
IntegerContext Context
The context type.
friend void shr(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
Real()
Creates a new floating point number.
Integer(long double d)
Creates a arbitrary precision integer from the given native floating point number.
bool isNonPositive(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being negative or zero.
friend int sign(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the sign of the given integer.
long ceilOfLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns .
friend int compareAbsValues(const Integer &a, const Integer &b)
Compares the two integers in absolute value.
Integer(const expressions::Expression< IntegerContext, A, O > &E)
Creates an integer from the given integer expression.
void setInfinity(Real &r, bool sign=true)
Sets the given floating point number to .
friend void mul(Integer &r, const Integer &a, const Integer &b)
Multiplies a with b and stores the result in r.
Real getEuler() const
Returns an approximation of the Euler number for the current context.
unsigned long getRealPrecision() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the precision of this context.
friend void decrement(Real &r, const Real &a)
Decrements a by one and stores the result in r.
friend void log2(Real &res, const Real &a)
Computes the logarithm of a to base 2 and stores the result in res.
friend long ceilOfLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Computes and returns .
Represents an arbitrary precision integer.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::SqrtOp > sqrt(const Real &i)
Returns the square root of the given floating point number.
void randomizeSeed()
Initializes this random number generator with a random seed.
friend void GCD(Integer &r, const Integer &x, const Integer &y)
Computes the non-negative Greatest Common Divisior r of x and y.
void assignTo(typename Context::Type &x) const
Evaluates the expression into the given object.
friend bool isNonPositive(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being negative or zero.
friend void sqrt(Real &res, const Real &a)
Computes the square root of a and stores the result in res.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::LGammaOp > lgamma(const Real &i)
Returns the natural logarithm of the absolute value of the Gamma function evaluated at the given floa...
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.
friend long approxLog2(const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Quickly approximates and returns the approximation.
friend bool isZero(const Integer &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being zero.
Real randomUniform(const RealContext &rc)
Creates and returns a uniformly distributed floating point number in the interval ...
UniformRNG(RandomNumberGenerator &rng) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new uniform random number generator based on the given random number generator.
Integer randomLen(unsigned long bits, const IntegerContext &ic)
Creates a random integer of a fixed bit length.
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.
friend bool isPositive(const Real &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Real object for being strictly positive.
friend void addmul(Real &r, const Real &a, const Real &b)
Multiplies a and b and adds the result to r.
void randomBits(void *ptr, unsigned long count)
Writes a given number of random bytes to the memory location pointed to.
Real(long double d)
Creates a new floating point number from the given native floating point number.
friend bool operator<=(const Real &a, const Real &b)
Compares the two floating point numbers a and b.
Represents an arithmetic context for arbitrary precision integer.
friend void asin(Real &res, const Real &a)
Computes the arcsine of a and stores the result in res.
void sub(Integer &r, const Integer &a, const Integer &b)
Subtracts b from a and stores the result in r.