plll
1.0
|
Represents a rational number as a quotient of two arbitrary precision integers. More...
#include <rational.hpp>
Public Member Functions | |
const Integer & | denominator () const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Retrieves the denominator of this rational number. More... | |
long | getApproxExponent () const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Returns approximate e such that |x| is approximately . More... | |
const Integer & | numerator () const PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Retrieves the numerator of this rational number. More... | |
Rational & | operator= (const Rational &r) |
Assigns the given rational number r to this rational number. More... | |
template<class A , template< typename, typename > class O> | |
Rational & | operator= (const expressions::Expression< RationalContext, A, O > &E) |
Assigns the rational expression E to this rational number. More... | |
template<class A , template< typename, typename > class O> | |
Rational & | operator= (const expressions::Expression< IntegerContext, A, O > &E) |
Assigns the integer expression E to this rational number. More... | |
Rational () | |
Creates a new rational number representing 0. | |
Rational (const RationalContext &rc) | |
Creates a new rational number representing 0. More... | |
Rational (const Rational &r) | |
Creates a copy of the given rational number. More... | |
Rational (const Rational &r, const RationalContext &rc) | |
Creates a copy of the given rational number. More... | |
template<class A , template< typename, typename > class O> | |
Rational (const expressions::Expression< RationalContext, A, O > &E) | |
Evaluates the given rational expression into a new rational number. More... | |
Rational (double d) | |
Creates a rational number from the given native floating point value. More... | |
Rational (double d, const RationalContext &rc) | |
Creates a rational number from the given native floating point value. More... | |
Rational (long double d) | |
Creates a rational number from the given native floating point value. More... | |
Rational (long double d, const RationalContext &rc) | |
Creates a rational number from the given native floating point value. More... | |
Rational (long i) | |
Creates a rational number from the given native integer. More... | |
Rational (long i, const RationalContext &rc) | |
Creates a rational number from the given native integer. More... | |
Rational (unsigned long i) | |
Creates a rational number from the given native integer. More... | |
Rational (unsigned long i, const RationalContext &rc) | |
Creates a rational number from the given native integer. More... | |
Rational (long long i) | |
Creates a rational number from the given native integer. More... | |
Rational (long long i, const RationalContext &rc) | |
Creates a rational number from the given native integer. More... | |
Rational (const Integer &n, const Integer &d) | |
Creates a rational number from the given arbitrary precision integer pair of numerator and denominator. More... | |
Rational (const Integer &i) | |
Creates a rational number from the given arbitrary precision integer expression. More... | |
Rational (const Integer &i, const RationalContext &rc) | |
Creates a rational number from the given arbitrary precision integer. More... | |
Static Public Member Functions | |
static unsigned long | precision () PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Retrieves the precision of the current rational number. More... | |
static void | setContext (const RationalContext &rc) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Applies the given rational context to this number. More... | |
Friends | |
void | abs (Rational &r, const Rational &a) |
Takes the absolute value of a and stores the result in r . More... | |
void | add (Rational &r, const Rational &a, const Rational &b) |
Adds a and b and stores the result in r . More... | |
void | addmul (Rational &r, const Rational &a, const Rational &b) |
Multiplies a and b and adds the result to r . More... | |
int | compare (const Rational &a, const Rational &b) |
Compares the two rational numbers. More... | |
int | compareAbsValues (const Rational &a, const Rational &b) |
Compares the two rational numbers in absolute value. More... | |
void | decrement (Rational &r, const Rational &a) |
Negates a and stores the result in r . More... | |
void | div (Rational &r, const Rational &a, const Rational &b) |
Divides a by b and stores the result in r . More... | |
void | increment (Rational &r, const Rational &a) |
Increments a by one and stores the result in r . More... | |
bool | isNegative (const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given rational number for being strictly negative. More... | |
bool | isNonNegative (const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given rational number for being positive or zero. More... | |
bool | isNonPositive (const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given rational number for being negative or zero. More... | |
bool | isOne (const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Real object for being zero. More... | |
bool | isPositive (const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given rational number for being strictly positive. More... | |
bool | isZero (const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given rational number for being zero. More... | |
void | makeAbs (Rational &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Makes the operand non-negative. More... | |
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 . More... | |
void | mul (Rational &r, const Rational &a, const Rational &b) |
Multiplies a with b and stores the result in r . More... | |
void | neg (Rational &r, const Rational &a) |
Negates a and stores the result in r . More... | |
std::ostream & | operator<< (std::ostream &s, const Rational &r) |
Outputs the rational number on the given output stream. | |
std::istream & | operator>> (std::istream &s, Rational &r) |
Reads the rational number from the given input stream. | |
void | power (Rational &r, const Rational &a, signed long e) |
Raises a to the power e and stores the result in r . More... | |
void | power (Rational &r, const Rational &a, unsigned long e) |
Raises a to the power e and stores the result in r . More... | |
void | power (Rational &r, const Rational &a, const Integer &e) |
Raises a to the power e and stores the result in r . More... | |
void | setOne (Rational &r) |
Sets the given rational number to one. More... | |
void | setZero (Rational &r, bool sign) |
Sets the given rational number to . More... | |
void | shl (Rational &r, const Rational &a, long b) |
Multiplies a by and stores the result in r . More... | |
void | shr (Rational &r, const Rational &a, long b) |
Multiplies a by and stores the result in r . More... | |
int | sign (const Rational &r) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Returns the sign of the given rational number. More... | |
void | square (Rational &r, const Rational &a) |
Computes the square of a and stores the result in r . More... | |
void | sub (Rational &r, const Rational &a, const Rational &b) |
Subtracts b from a and stores the result in r . More... | |
void | submul (Rational &r, const Rational &a, const Rational &b) |
Multiplies a and b and subtracts the result from r . More... | |
Represents a rational number as a quotient of two arbitrary precision integers.
Definition at line 431 of file rational.hpp.
|
inline |
Creates a new rational number representing 0.
rc | A rational context. |
Definition at line 542 of file rational.hpp.
|
inline |
Creates a copy of the given rational number.
r | The rational number to copy. |
Definition at line 553 of file rational.hpp.
|
inline |
Creates a copy of the given rational number.
r | The rational number to copy. |
rc | A rational context. |
Definition at line 564 of file rational.hpp.
|
inline |
Evaluates the given rational expression into a new rational number.
E | A rational expression. |
Definition at line 575 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native floating point value.
d | The native floating point value. |
Definition at line 607 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native floating point value.
d | The native floating point value. |
rc | A rational context. |
Definition at line 618 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native floating point value.
d | The native floating point value. |
Definition at line 628 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native floating point value.
d | The native floating point value. |
rc | A rational context. |
Definition at line 639 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native integer.
i | The native integer. |
Definition at line 649 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native integer.
i | The native integer. |
rc | A rational context. |
Definition at line 661 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native integer.
i | The native integer. |
Definition at line 672 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native integer.
i | The native integer. |
rc | A rational context. |
Definition at line 684 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native integer.
i | The native integer. |
Definition at line 695 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given native integer.
i | The native integer. |
rc | A rational context. |
Definition at line 707 of file rational.hpp.
Creates a rational number from the given arbitrary precision integer pair of numerator and denominator.
n | The numerator. |
d | The denominator. |
Definition at line 720 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given arbitrary precision integer expression.
i | The arbitrary precision integer. |
Definition at line 737 of file rational.hpp.
|
inlineexplicit |
Creates a rational number from the given arbitrary precision integer.
i | The arbitrary precision integer. |
rc | A rational context. |
Definition at line 756 of file rational.hpp.
|
inline |
Retrieves the denominator of this rational number.
arithmetic::Integer
object representing the denominator. Definition at line 498 of file rational.hpp.
|
inline |
Returns approximate e
such that |x| is approximately .
The value of e
should be OK up to +-2.
Definition at line 1419 of file rational.hpp.
|
inline |
Retrieves the numerator of this rational number.
arithmetic::Integer
object representing the numerator. Definition at line 488 of file rational.hpp.
Assigns the given rational number r
to this rational number.
r | The rational number to assign to this rational number. |
Definition at line 775 of file rational.hpp.
|
inline |
Assigns the rational expression E
to this rational number.
E | The rational expression. |
Definition at line 789 of file rational.hpp.
|
inline |
Assigns the integer expression E
to this rational number.
E | The integer expression. |
Definition at line 802 of file rational.hpp.
|
inlinestatic |
Retrieves the precision of the current rational number.
Will return a large number equal to the one returned by RationalContext::getRealPrecision()
.
Definition at line 586 of file rational.hpp.
|
inlinestatic |
Applies the given rational context to this number.
Does nothing.
rc | A rational context. |
Definition at line 598 of file rational.hpp.
Takes the absolute value of a
and stores the result in r
.
r | The result. |
a | The operand. |
Definition at line 1285 of file rational.hpp.
Adds a
and b
and stores the result in r
.
r | The result. |
a | The first operand. |
b | The second operand. |
Definition at line 887 of file rational.hpp.
Multiplies a
and b
and adds the result to r
.
r | The accumulator. |
a | The first operand. |
b | The second operand. |
Definition at line 1256 of file rational-ops.hpp.
Compares the two rational numbers.
a | The first operand. |
b | The second operand. |
Definition at line 1320 of file rational.hpp.
Compares the two rational numbers in absolute value.
a | The first operand. |
b | The second operand. |
Definition at line 1331 of file rational.hpp.
Negates a
and stores the result in r
.
r | The result. |
a | The operand. |
Definition at line 1265 of file rational.hpp.
Divides a
by b
and stores the result in r
.
r | The result. |
a | The first operand. |
b | The second operand. |
Definition at line 1081 of file rational.hpp.
Increments a
by one and stores the result in r
.
r | The result. |
a | The operand. |
Definition at line 1258 of file rational.hpp.
|
friend |
Tests the given rational number for being strictly negative.
true
if and only if the argument is strictly negative. Definition at line 829 of file rational.hpp.
|
friend |
Tests the given rational number for being positive or zero.
true
if and only if the argument is positive or zero. Definition at line 824 of file rational.hpp.
|
friend |
Tests the given rational number for being negative or zero.
true
if and only if the argument is negative or zero. Definition at line 834 of file rational.hpp.
|
friend |
Tests the given plll::arithmetic::Real
object for being zero.
true
if and only if the argument is zero. Definition at line 814 of file rational.hpp.
|
friend |
Tests the given rational number for being strictly positive.
true
if and only if the argument is strictly positive. Definition at line 819 of file rational.hpp.
|
friend |
Tests the given rational number for being zero.
true
if and only if the argument is zero. Definition at line 809 of file rational.hpp.
|
friend |
Makes the operand non-negative.
a | The operand. |
Definition at line 1298 of file rational.hpp.
Takes the remainder of the division of a
by b
and stores it in r
.
r | The result. |
a | The first operand. |
b | The second operand. |
Definition at line 1171 of file rational.hpp.
Multiplies a
with b
and stores the result in r
.
r | The result. |
a | The first operand. |
b | The second operand. |
Definition at line 1008 of file rational.hpp.
Negates a
and stores the result in r
.
r | The result. |
a | The operand. |
Definition at line 1272 of file rational.hpp.
Raises a
to the power e
and stores the result in r
.
r | The result. |
a | The base. |
e | The exponent. |
Definition at line 1361 of file rational.hpp.
Raises a
to the power e
and stores the result in r
.
r | The result. |
a | The base. |
e | The exponent. |
Definition at line 1381 of file rational.hpp.
Raises a
to the power e
and stores the result in r
.
r | The result. |
a | The base. |
e | The exponent. |
|
friend |
Sets the given rational number to one.
r | The rational number variable to set to one. |
Definition at line 1313 of file rational.hpp.
|
friend |
Sets the given rational number to .
Note that the sign is ignored, as there is no distinction between the rational +0 and -0.
r | The rational number variable to set to zero. |
sign | This is ignored. The default value is true . |
Definition at line 1306 of file rational.hpp.
Multiplies a
by and stores the result in r
.
r | The result. |
a | The first operand. |
b | The second operand. |
Definition at line 1194 of file rational.hpp.
Multiplies a
by and stores the result in r
.
r | The result. |
a | The first operand. |
b | The second operand. |
Definition at line 1226 of file rational.hpp.
|
friend |
Returns the sign of the given rational number.
Definition at line 1342 of file rational.hpp.
Computes the square of a
and stores the result in r
.
r | The result. |
a | The operand. |
Definition at line 1348 of file rational.hpp.
Subtracts b
from a
and stores the result in r
.
r | The result. |
a | The first operand. |
b | The second operand. |
Definition at line 918 of file rational.hpp.
Multiplies a
and b
and subtracts the result from r
.
r | The accumulator. |
a | The first operand. |
b | The second operand. |
Definition at line 1262 of file rational-ops.hpp.