23 #ifndef PLLL_INCLUDE_GUARD__RATIONAL_HPP
24 #define PLLL_INCLUDE_GUARD__RATIONAL_HPP
47 class RationalContext;
58 inline bool isZero(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
66 inline bool isOne(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
74 inline bool isPositive(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
82 inline bool isNonNegative(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
90 inline bool isNegative(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
98 inline bool isNonPositive(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
111 inline void add(Rational & r,
const Rational & a,
const Rational & b);
120 inline void sub(Rational & r,
const Rational & a,
const Rational & b);
129 inline void addmul(Rational & r,
const Rational & a,
const Rational & b);
138 inline void submul(Rational & r,
const Rational & a,
const Rational & b);
147 inline void mul(Rational & r,
const Rational & a,
const Rational & b);
156 inline void div(Rational & r,
const Rational & a,
const Rational & b);
165 inline void mod(Rational & r,
const Rational & a,
const Rational & b);
174 inline void shl(Rational & r,
const Rational & a,
long b);
183 inline void shr(Rational & r,
const Rational & a,
long b);
191 inline void increment(Rational & r,
const Rational & a);
199 inline void decrement(Rational & r,
const Rational & a);
207 inline void neg(Rational & r,
const Rational & a);
215 inline void abs(Rational & r,
const Rational & a);
223 inline void square(Rational & r,
const Rational & a);
234 inline void makeAbs(Rational & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
243 std::ostream &
operator << (std::ostream & s,
const Rational & r);
248 std::istream &
operator >> (std::istream & s, Rational & r);
263 inline void setZero(Rational & r,
bool sign =
true);
270 inline void setOne(Rational & r);
284 inline int compare(
const Rational & a,
const Rational & b);
307 inline int sign(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
320 inline void power(Rational & r,
const Rational & a,
signed long e);
329 inline void power(Rational & r,
const Rational & a,
unsigned long e);
338 void power(Rational & r,
const Rational & a,
const Integer & e);
347 inline void swap(Rational &, Rational &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
360 enum { d_precision = 21474836479 };
375 enum { is_cputype =
false, is_realtype =
true, is_inttype =
false, is_exact =
true, is_variable_precision =
false,
376 has_squareroot =
false, has_full_power =
false, has_special_fns =
false, has_huge_exponent =
true,
377 has_infinity =
false, has_uniform_rng =
false, has_constants =
false, has_trigonometric =
false };
393 static inline void setRealPrecision(
unsigned long prec) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
433 #ifndef PLLL_INTERNAL_NO_TEMPLATE_FRIENDS
434 template<
class X,
class Y>
446 inline void normalize()
456 void initFromDouble(
double d)
458 const int MantissaBitsInDouble = std::numeric_limits<double>::digits + 2;
460 d = std::frexp(d, &e);
465 shl(*
this, *
this, e - MantissaBitsInDouble);
468 void initFromDouble(
long double d)
470 const int MantissaBitsInDouble = std::numeric_limits<long double>::digits + 2;
472 d = std::frexp(d, &e);
477 shl(*
this, *
this, e - MantissaBitsInDouble);
512 #if __cplusplus >= 201103L
519 inline Rational(Rational && r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
520 : d_num(std::move(r.d_num)), d_denom(std::move(r.d_denom))
529 Rational &
operator = (Rational && r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
531 d_num = std::move(r.d_num);
532 d_denom = std::move(r.d_denom);
554 : d_num(r.d_num), d_denom(r.d_denom)
565 : d_num(r.d_num), d_denom(r.d_denom)
574 template<
class A,
template<
typename,
typename>
class O>
586 static inline unsigned long precision() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
588 return RationalContext::d_precision;
721 : d_num(n), d_denom(d)
725 neg(d_denom, d_denom);
743 template<
class Data,
template<
typename,
typename>
class Op>
762 template<
class Data,
template<
typename,
typename>
class Op>
788 template<
class A,
template<
typename,
typename>
class O>
801 template<
class A,
template<
typename,
typename>
class O>
809 inline friend bool isZero(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
814 inline friend bool isOne(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
819 inline friend bool isPositive(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
824 inline friend bool isNonNegative(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
829 inline friend bool isNegative(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
834 inline friend bool isNonPositive(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
840 inline void add_r_neq_1st(
const Rational & a,
const Rational & b)
844 GCD(g1, a.d_denom, b.d_denom);
847 d_num = b.d_num * a.d_denom;
848 d_num += a.d_num * b.d_denom;
849 d_denom = a.d_denom * b.d_denom;
853 Integer t = a.d_denom / g1;
856 d_num += a.d_num * t;
857 d_denom = a.d_denom * t;
862 inline void sub_r_neq_1st(
const Rational & a,
const Rational & b,
bool compute_negative)
866 GCD(g1, a.d_denom, b.d_denom);
869 d_num = b.d_num * a.d_denom;
870 d_num -= a.d_num * b.d_denom;
871 d_denom = a.d_denom * b.d_denom;
875 Integer t = a.d_denom / g1;
878 d_num -= a.d_num * t;
879 d_denom = a.d_denom * t;
881 if (!compute_negative)
887 inline friend void add(Rational & r,
const Rational & a,
const Rational & b)
894 if (
bit(r.d_denom, 0))
900 r.add_r_neq_1st(b, a);
903 r.add_r_neq_1st(a, b);
906 template<
typename IntIntExpr>
907 inline friend void add_z(Rational & r,
const Rational & a,
const IntIntExpr & b)
910 r.d_num += b * r.d_denom;
913 r.d_num = a.d_num + b * a.d_denom;
914 r.d_denom = a.d_denom;
918 inline friend void sub(Rational & r,
const Rational & a,
const Rational & b)
929 r.sub_r_neq_1st(b, a,
true);
932 r.sub_r_neq_1st(a, b,
false);
935 template<
typename IntIntExpr>
936 inline friend void sub_z(Rational & r,
const Rational & a,
const IntIntExpr & b)
939 r.d_num -= b * r.d_denom;
943 r.d_num -= b * a.d_denom;
944 r.d_denom = a.d_denom;
948 template<
typename IntIntExpr>
949 inline friend void z_sub(Rational & r,
const IntIntExpr & a,
const Rational & b)
953 r.d_num -= a * r.d_denom;
954 neg(r.d_num, r.d_num);
958 r.d_num = a * b.d_denom;
960 r.d_denom = b.d_denom;
964 inline friend void addmul(Rational & r,
const Rational & a,
const Rational & b);
965 inline friend void submul(Rational & r,
const Rational & a,
const Rational & b);
967 template<
typename IntIntExpr>
968 inline friend void addmul_z(Rational & r,
const Rational & a,
const IntIntExpr & b)
972 r.d_denom *= r.d_num;
974 r.d_num = b +
convert(1u, IntegerContext());
975 r.d_num *= r.d_denom;
979 Integer t = r.d_denom * a.d_num;
981 r.d_num *= a.d_denom;
983 r.d_denom *= a.d_denom;
987 template<
typename IntIntExpr>
988 inline friend void submul_z(Rational & r,
const Rational & a,
const IntIntExpr & b)
992 r.d_denom *= r.d_num;
994 neg(r.d_num, r.d_num);
995 r.d_num = b +
convert(1u, IntegerContext());
996 r.d_num *= r.d_denom;
1000 Integer t = r.d_denom * a.d_num;
1002 r.d_num *= a.d_denom;
1004 r.d_denom *= a.d_denom;
1008 inline friend void mul(Rational & r,
const Rational & a,
const Rational & b)
1018 GCD(g1, a.d_num, b.d_denom);
1019 GCD(g2, b.d_num, a.d_denom);
1024 r.d_num = a.d_num * b.d_num;
1025 r.d_denom = a.d_denom * b.d_denom;
1030 r.d_num = a.d_num * t;
1032 r.d_denom = b.d_denom * t;
1040 r.d_num = b.d_num * t;
1042 r.d_denom = a.d_denom * t;
1047 r.d_num = a.d_num / g1;
1050 r.d_denom = b.d_denom / g1;
1058 template<
typename IntIntExpr>
1059 inline friend void mul_z(Rational & r,
const Rational & a,
const IntIntExpr & b)
1069 GCD(g, a.d_denom, b);
1071 r.d_num = a.d_num * b;
1075 r.d_num = a.d_num * g;
1077 r.d_denom = a.d_denom;
1081 inline friend void div(Rational & r,
const Rational & a,
const Rational & b)
1092 swap(r.d_num, r.d_denom);
1093 if (
sign(r.d_denom) < 0)
1094 r.d_denom = -r.d_denom;
1096 r.d_denom *= a.d_denom;
1103 if (
sign(b.d_num) < 0)
1105 r.d_num *= b.d_denom;
1107 r.d_denom *= b.d_num;
1108 r.d_denom = -r.d_denom;
1112 r.d_num *= b.d_denom;
1113 r.d_denom *= b.d_num;
1119 if (
sign(b.d_num) < 0)
1121 r.d_num = a.d_num * b.d_denom;
1123 r.d_denom = a.d_denom * b.d_num;
1124 r.d_denom = -r.d_denom;
1128 r.d_num = a.d_num * b.d_denom;
1129 r.d_denom = a.d_denom * b.d_num;
1136 template<
typename IntIntExpr>
1137 inline friend void div_z(Rational & r,
const Rational & a,
const IntIntExpr & b)
1149 r.d_denom = a.d_denom * b;
1153 r.d_denom = a.d_denom * g;
1159 template<
typename IntIntExpr>
1160 inline friend void z_div(Rational & r,
const IntIntExpr & a,
const Rational & b)
1163 swap(r.d_num, r.d_denom);
1164 if (
sign(r.d_denom) < 0)
1166 neg(r.d_num, r.d_num);
1171 inline friend void mod(Rational & r,
const Rational & a,
const Rational & b)
1174 r.d_denom = a.d_denom * b.d_denom;
1178 template<
typename IntIntExpr>
1179 inline friend void mod_z(Rational & r,
const Rational & a,
const IntIntExpr & b)
1182 r.d_denom = a.d_denom;
1186 template<
typename IntIntExpr>
1187 inline friend void z_mod(Rational & r,
const IntIntExpr & a,
const Rational & b)
1190 r.d_denom = b.d_denom;
1194 inline friend void shl(Rational & r,
const Rational & a,
long b)
1198 r.d_num = a.d_num << b;
1199 r.d_denom = a.d_denom;
1204 r.d_denom = a.d_denom << (-b);
1209 template<
typename IntIntExpr>
1210 inline friend void shl_z(Rational & r,
const IntIntExpr & a,
long b)
1226 inline friend void shr(Rational & r,
const Rational & a,
long b)
1231 r.d_denom = a.d_denom << b;
1235 r.d_num = a.d_num << (-b);
1236 r.d_denom = a.d_denom;
1241 template<
typename IntIntExpr>
1242 inline friend void shr_z(Rational & r,
const IntIntExpr & a,
long b)
1246 r.d_num = a.d_num << -b;
1258 inline friend void increment(Rational & r,
const Rational & a)
1260 r.d_num = a.d_num + a.d_denom;
1261 r.d_denom = a.d_denom;
1265 inline friend void decrement(Rational & r,
const Rational & a)
1267 r.d_num = a.d_num - a.d_denom;
1268 r.d_denom = a.d_denom;
1272 inline friend void neg(Rational & r,
const Rational & a)
1274 neg(r.d_num, a.d_num);
1275 r.d_denom = a.d_denom;
1278 template<
typename IntIntExpr>
1279 inline friend void neg_z(Rational & r,
const IntIntExpr & a)
1285 inline friend void abs(Rational & r,
const Rational & a)
1287 abs(r.d_num, a.d_num);
1288 r.d_denom = a.d_denom;
1291 template<
typename IntIntExpr>
1292 inline friend void abs_z(Rational & r,
const IntIntExpr & a)
1298 inline friend void makeAbs(Rational & a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1303 friend std::ostream &
operator << (std::ostream & s,
const Rational & r);
1304 friend std::istream &
operator >> (std::istream & s, Rational & r);
1320 inline friend int compare(
const Rational & a,
const Rational & b)
1322 return compare(a.d_num * b.d_denom, b.d_num * a.d_denom);
1325 template<
typename IntIntExpr>
1326 inline friend int compare_z(
const Rational & a,
const IntIntExpr & b)
1328 return compare(a.d_num, b * a.d_denom);
1336 template<
typename IntIntExpr>
1337 inline friend int compareAbsValues_z(
const Rational & a,
const IntIntExpr & b)
1342 inline friend int sign(
const Rational & r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1345 return sign(r.d_num);
1348 inline friend void square(Rational & r,
const Rational & a)
1350 square(r.d_num, a.d_num);
1351 square(r.d_denom, a.d_denom);
1354 template<
typename IntIntExpr>
1355 inline friend void square_z(Rational & r,
const IntIntExpr & a)
1361 inline friend void power(Rational & r,
const Rational & a,
signed long e)
1366 template<
typename IntIntExpr>
1367 inline friend void power_z(Rational & r,
const IntIntExpr & a,
signed long e)
1371 power(r.d_num, a, e);
1376 power(r.d_denom, a, -e);
1381 inline friend void power(Rational & r,
const Rational & a,
unsigned long e)
1386 template<
typename IntIntExpr>
1387 inline friend void power_z(Rational & r,
const IntIntExpr & a,
unsigned long e)
1389 power(r.d_num, a, e);
1393 friend void power(Rational & r,
const Rational & a,
const Integer & e);
1395 template<
typename IntIntExpr>
1396 inline friend void power_z(Rational & r,
const IntIntExpr & a,
const Integer & e)
1400 power(r.d_num, a, e);
1405 power(r.d_denom, a, -e);
1410 inline friend void arithmetic::swap(Rational &, Rational &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE;
1425 template<
typename IntIntExpr>
1426 inline void add_z(Rational & r,
const Rational & a,
const IntIntExpr & b);
1428 template<
typename IntIntExpr>
1429 inline void sub_z(Rational & r,
const Rational & a,
const IntIntExpr & b);
1431 template<
typename IntIntExpr>
1432 inline void z_sub(Rational & r,
const IntIntExpr & a,
const Rational & b);
1434 template<
typename IntIntExpr>
1435 inline void addmul_z(Rational & r,
const Rational & a,
const IntIntExpr & b);
1437 template<
typename IntIntExpr>
1438 inline void submul_z(Rational & r,
const Rational & a,
const IntIntExpr & b);
1440 template<
typename IntIntExpr>
1441 inline void mul_z(Rational & r,
const Rational & a,
const IntIntExpr & b);
1443 template<
typename IntIntExpr>
1444 inline void div_z(Rational & r,
const Rational & a,
const IntIntExpr & b);
1446 template<
typename IntIntExpr>
1447 inline void z_div(Rational & r,
const IntIntExpr & a,
const Rational & b);
1449 template<
typename IntIntExpr>
1450 inline void mod_z(Rational & r,
const Rational & a,
const IntIntExpr & b);
1452 template<
typename IntIntExpr>
1453 inline void z_mod(Rational & r,
const IntIntExpr & a,
const Rational & b);
1455 template<
typename IntIntExpr>
1456 inline void shl_z(Rational & r,
const IntIntExpr & a,
long b);
1458 template<
typename IntIntExpr>
1459 inline void shr_z(Rational & r,
const IntIntExpr & a,
long b);
1461 template<
typename IntIntExpr>
1462 inline void neg_z(Rational & r,
const IntIntExpr & a);
1464 template<
typename IntIntExpr>
1465 inline void abs_z(Rational & r,
const IntIntExpr & a);
1467 template<
typename IntIntExpr>
1468 inline int compare_z(
const Rational & a,
const IntIntExpr & b);
1470 template<
typename IntIntExpr>
1471 inline int compareAbsValues_z(
const Rational & a,
const IntIntExpr & b);
1473 template<
typename IntIntExpr>
1474 inline void square_z(Rational & r,
const IntIntExpr & a);
1476 template<
typename IntIntExpr>
1477 inline void power_z(Rational & r,
const IntIntExpr & a,
signed long e);
1479 template<
typename IntIntExpr>
1480 inline void power_z(Rational & r,
const IntIntExpr & a,
unsigned long e);
1482 template<
typename IntIntExpr>
1483 inline void power_z(Rational & r,
const IntIntExpr & a,
const Integer & e);
1485 inline void swap(Rational & a, Rational & b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
1487 swap(a.d_num, b.d_num);
1488 swap(a.d_denom, b.d_denom);
friend void power(Rational &r, const Rational &a, signed long e)
Raises a to the power e 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.
Rational(const Rational &r, const RationalContext &rc)
Creates a copy of the given rational number.
Rational Real
The rational type.
Rational(long long i)
Creates a rational number from the given native integer.
long getApproxExponent() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns approximate e such that |x| is approximately .
friend bool isNegative(const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given rational number for being strictly negative.
Rational(const RationalContext &rc)
Creates a new rational number representing 0.
bool isZero(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being zero.
Rational(const Rational &r)
Creates a copy of the given rational number.
Rational(const Integer &i)
Creates a rational number from the given arbitrary precision integer expression.
Rational(unsigned long i, const RationalContext &rc)
Creates a rational number from the given native integer.
friend bool isNonNegative(const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given rational number for being positive or zero.
int bit(const Integer &x, long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the n bit of in the usual binary representation.
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.
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.
Rational(long double d, const RationalContext &rc)
Creates a rational number from the given native floating point value.
friend void mul(Rational &r, const Rational &a, const Rational &b)
Multiplies a with b and stores the result in r.
Conversion definitions for rational numbers.
bool isOne(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being one.
friend void shl(Rational &r, const Rational &a, long b)
Multiplies a by and stores the result in r.
friend void setOne(Rational &r)
Sets the given rational number to one.
RationalContext() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Creates a new rational context.
friend void increment(Rational &r, const Rational &a)
Increments a by one and stores the result in r.
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::ShLOp > operator<<(const Integer &a, const Integer &b)
Computes the bitwise left shift of the first integer by the number of bits given by the second intege...
friend void square(Rational &r, const Rational &a)
Computes the square of a and stores the result in r.
Rational(long double d)
Creates a rational number from the given native floating point value.
Rational(long i, const RationalContext &rc)
Creates a rational number from the given native integer.
friend void makeAbs(Rational &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Makes the operand non-negative.
Operator definitions for rational numbers.
Rational & operator=(const Rational &r)
Assigns the given rational number r to this rational number.
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.
friend int sign(const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the sign of the given rational number.
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...
friend void div(Rational &r, const Rational &a, const Rational &b)
Divides a by b and stores the result in r.
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 void add(Rational &r, const Rational &a, const Rational &b)
Adds a and b and stores the result in r.
Rational(long i)
Creates a rational number from the given native integer.
friend void sub(Rational &r, const Rational &a, const Rational &b)
Subtracts b from a and stores the result in r.
friend std::istream & operator>>(std::istream &s, Rational &r)
Reads the rational number from the given input stream.
static unsigned long getMaxRealPrecision() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the maximal possible precision for this context.
Rational(const expressions::Expression< RationalContext, A, O > &E)
Evaluates the given rational expression into a new rational number.
friend void neg(Rational &r, const Rational &a)
Negates a and stores the result in r.
Implementation backend for conversions from context types to native types.
Represents a rational number as a quotient of two arbitrary precision integers.
void swap(plll::arithmetic::Integer &, plll::arithmetic::Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Swaps two plll::arithmetic::Integer objects.
const Integer & numerator() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Retrieves the numerator of this rational number.
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.
Rational(const Integer &i, const RationalContext &rc)
Creates a rational number from the given arbitrary precision integer.
Rational(unsigned long i)
Creates a rational number from the given native integer.
Represents an expression.
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.
friend void mod(Rational &r, const Rational &a, const Rational &b)
Takes the remainder of the division of a by b and stores it in r.
int sign(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the sign of the given integer.
friend std::ostream & operator<<(std::ostream &s, const Rational &r)
Outputs the rational number on the given output stream.
friend void abs(Rational &r, const Rational &a)
Takes the absolute value of a and stores the result in r.
friend bool isPositive(const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given rational number for being strictly positive.
static void setRealPrecision(unsigned long prec) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Sets the precision of this context. (Will do nothing.)
friend bool isOne(const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Real object for being zero.
void shl(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
friend void setZero(Rational &r, bool sign)
Sets the given rational number to .
static unsigned long precision() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Retrieves the precision of the current rational number.
static unsigned long getRealPrecision() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the precision of this context.
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...
Rational()
Creates a new rational number representing 0.
void neg(Integer &r, const Integer &a)
Negates a and stores the result in r.
Rational Type
The rational type.
void addmul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and adds the result to r.
Rational(double d, const RationalContext &rc)
Creates a rational number from the given native floating point value.
friend bool isNonPositive(const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given rational number for being negative or zero.
bool isPositive(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given plll::arithmetic::Integer object for being strictly positive.
friend void addmul(Rational &r, const Rational &a, const Rational &b)
Multiplies a and b and adds the result to r.
static void setContext(const RationalContext &rc) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Applies the given rational context to this number.
void add(Integer &r, const Integer &a, const Integer &b)
Adds a and b and stores the result in r.
friend bool isZero(const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Tests the given rational number for being zero.
Rational(const Integer &n, const Integer &d)
Creates a rational number from the given arbitrary precision integer pair of numerator and denominato...
void makeAbs(Integer &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Makes the operand non-negative.
const Integer & denominator() const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Retrieves the denominator of this rational number.
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.
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 .
friend void submul(Rational &r, const Rational &a, const Rational &b)
Multiplies a and b and subtracts the result from r.
Rational(double d)
Creates a rational number from the given native floating point value.
static unsigned long getMinRealPrecision() PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the minimal possible precision for this context.
Represents an arbitrary precision integer.
void assignTo(typename Context::Type &x) const
Evaluates the expression into the given object.
friend int compareAbsValues(const Rational &a, const Rational &b)
Compares the two rational numbers in absolute value.
friend int compare(const Rational &a, const Rational &b)
Compares the two rational numbers.
friend void shr(Rational &r, const Rational &a, long b)
Multiplies a by and stores the result in r.
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.
Represents an arithmetic context for rational numbers.
Represents an arithmetic context for arbitrary precision integer.
friend void decrement(Rational &r, const Rational &a)
Negates a and stores the result in r.
void sub(Integer &r, const Integer &a, const Integer &b)
Subtracts b from a and stores the result in r.
Rational(long long i, const RationalContext &rc)
Creates a rational number from the given native integer.