LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
|
Exact rational number. More...
#include <rational.hpp>
Public Member Functions | |
rational () noexcept | |
Empty constructor. | |
rational (int64_t n, uint64_t d=1) noexcept | |
Constructor with numerator and denominator. | |
rational (const integer &n, const integer &d=1) noexcept | |
Constructor with numerator and denominator. | |
rational (const std::string &s) noexcept | |
Constructor with string. | |
rational (const rational &r) noexcept | |
Copy constructor. | |
rational (integer &&v) noexcept | |
Move constructor. | |
rational (integer &&n, integer &&d) noexcept | |
Move constructor with numerator and denominator. | |
rational (rational &&r) noexcept | |
Move constructor. | |
~rational () noexcept | |
Destructor. | |
void | set_si (int64_t n, uint64_t d=1) noexcept |
Overwrites the value of this rational with \(n/d\). | |
void | set_ui (uint64_t n, uint64_t d=1) noexcept |
Overwrites the value of this rational with \(n/d\). | |
void | set_str (const std::string &s) noexcept |
Overwrites the value in the string s. | |
void | set_integer (const integer &n, const integer &d) noexcept |
Overwrites the value of this rational with the value \(n/d\). | |
void | set_rational (const rational &r) noexcept |
Overwrites the value of this rational with the value \(n/d\). | |
void | invert () noexcept |
Changes numerator and denominator. | |
rational & | operator= (int64_t i) noexcept |
Assignment operator. | |
rational & | operator= (const std::string &s) noexcept |
Assignment operator. | |
rational & | operator= (const integer &i) noexcept |
Assignment operator. | |
rational & | operator= (const rational &r) noexcept |
Assignment operator. | |
rational & | operator= (integer &&i) noexcept |
Move assignment operator. | |
rational & | operator= (rational &&r) noexcept |
Move assignment operator. | |
bool | operator== (int64_t i) const noexcept |
Equality operator. | |
bool | operator== (const integer &i) const noexcept |
Equality operator. | |
bool | operator== (const rational &r) const noexcept |
Equality operator. | |
bool | operator!= (int64_t i) const noexcept |
Non-equality operator. | |
bool | operator!= (const integer &i) const noexcept |
Non-equality operator. | |
bool | operator!= (const rational &r) const noexcept |
Non-equality operator. | |
bool | operator< (int64_t i) const noexcept |
Less than operator. | |
bool | operator< (const integer &i) const noexcept |
Less than operator. | |
bool | operator< (const rational &r) const noexcept |
Less than operator. | |
bool | operator<= (int64_t i) const noexcept |
Less than or equal to operator. | |
bool | operator<= (const integer &i) const noexcept |
Less than or equal to operator. | |
bool | operator<= (const rational &r) const noexcept |
Less than or equal to operator. | |
bool | operator> (int64_t i) const noexcept |
Greater than operator. | |
bool | operator> (const integer &i) const noexcept |
Greater than operator. | |
bool | operator> (const rational &r) const noexcept |
Greater than operator. | |
bool | operator>= (int64_t i) const noexcept |
Greater than or equal to operator. | |
bool | operator>= (const integer &i) const noexcept |
Greater than or equal to operator. | |
bool | operator>= (const rational &r) const noexcept |
Greater than or equal to operator. | |
rational | operator+ (int64_t i) const noexcept |
Addition operator. | |
rational | operator+ (const integer &i) const noexcept |
Addition operator. | |
rational | operator+ (const rational &r) const noexcept |
Addition operator. | |
rational & | operator+= (int64_t i) noexcept |
Addition operator. | |
rational & | operator+= (const integer &i) noexcept |
Addition operator. | |
rational & | operator+= (const rational &r) noexcept |
Addition operator. | |
rational | operator- () const noexcept |
Substraction unary operator. | |
rational | operator- (int64_t i) const noexcept |
Substraction operator. | |
rational | operator- (const integer &i) const noexcept |
Substraction operator. | |
rational | operator- (const rational &r) const noexcept |
Substraction operator. | |
rational & | operator-= (int64_t i) noexcept |
Substraction operator. | |
rational & | operator-= (const integer &i) noexcept |
Substraction operator. | |
rational & | operator-= (const rational &r) noexcept |
Substraction operator. | |
rational | operator* (int64_t i) const noexcept |
Multiplication operator. | |
rational | operator* (const integer &i) const noexcept |
Multiplication operator. | |
rational | operator* (const rational &r) const noexcept |
Multiplication operator. | |
rational & | operator*= (int64_t i) noexcept |
Multiplication operator. | |
rational & | operator*= (const integer &i) noexcept |
Multiplication operator. | |
rational & | operator*= (const rational &r) noexcept |
Multiplication operator. | |
rational | operator/ (int64_t i) const noexcept |
Division operator. | |
rational | operator/ (const integer &i) const noexcept |
Division operator. | |
rational | operator/ (const rational &r) const noexcept |
Division operator. | |
rational & | operator/= (int64_t i) noexcept |
Division operator. | |
rational & | operator/= (const integer &i) noexcept |
Division operator. | |
rational & | operator/= (const rational &r) noexcept |
Division operator. | |
rational | pow (uint64_t i) const noexcept |
Exponentiation operator. | |
rational | pow (const integer &i) const noexcept |
Exponentiation operator. | |
rational & | powt (uint64_t i) noexcept |
Exponentiation operator. | |
rational & | powt (const integer &i) noexcept |
Exponentiation operator. | |
bool | is_initialized () const noexcept |
Returns whether this object is initialised or not. | |
int32_t | get_sign () const noexcept |
Returns the sign of this rational. | |
size_t | bytes () const noexcept |
Returns the amount of bytes this integer occupies. | |
integer | to_integer () const noexcept |
Converts this rational to an integer value. | |
void | as_integer (integer &i) const noexcept |
Converts this rational to an integer value. | |
double | to_double () const noexcept |
Converts this rational to a double-precision floating-point value. | |
void | as_double (double &d) const noexcept |
Converts this rational to a double-precision floating-point value. | |
std::string | to_string () const noexcept |
Converts this integer to a string. | |
void | as_string (std::string &s) const noexcept |
Converts this integer to a string. | |
integer | get_numerator () const noexcept |
Returns the numerator of this rational number. | |
integer | get_denominator () const noexcept |
Returns the denominator of this rational number. | |
void | swap (rational &r) noexcept |
Swaps the value of this rational with rational r's value. | |
Private Attributes | |
mpq_t | m_val |
Structure from GMP storing the rational's value. | |
bool | m_initialized = true |
Is this rational initialised? | |
Friends | |
bool | operator== (int64_t i, const rational &r) noexcept |
Equality operator. | |
bool | operator== (const integer &i, const rational &r) noexcept |
Equality operator. | |
bool | operator!= (int64_t i, const rational &r) noexcept |
Non-equality operator. | |
bool | operator!= (const integer &i, const rational &r) noexcept |
Non-equality operator. | |
bool | operator< (int64_t i, const rational &r) noexcept |
Less than operator. | |
bool | operator< (const integer &i, const rational &r) noexcept |
Less than operator. | |
bool | operator<= (int64_t i, const rational &r) noexcept |
Less than or equal to operator. | |
bool | operator<= (const integer &i, const rational &r) noexcept |
Less than or equal to operator. | |
bool | operator> (int64_t i, const rational &r) noexcept |
Greater than operator. | |
bool | operator> (const integer &i, const rational &r) noexcept |
Greater than operator. | |
bool | operator>= (int64_t i, const rational &r) noexcept |
Greater than or equal to operator. | |
bool | operator>= (const integer &i, const rational &r) noexcept |
Greater than or equal to operator. | |
rational | operator+ (int64_t i, const rational &r) noexcept |
Addition operator. | |
rational | operator+ (const integer &i, const rational &r) noexcept |
Addition operator. | |
rational | operator- (int64_t i, const rational &r) noexcept |
Substraction operator. | |
rational | operator- (const integer &i, const rational &r) noexcept |
Substraction operator. | |
rational | operator* (int64_t i, const rational &r) noexcept |
Multiplication operator. | |
rational | operator* (const integer &i, const rational &r) noexcept |
Multiplication operator. | |
rational | operator/ (int64_t i, const rational &r) noexcept |
Division operator. | |
void | swap (rational &r1, rational &r2) noexcept |
Swaps two rationals. | |
Exact rational number.
This class wraps the mpq_t data structure from GMP with operators for an easy usage.
|
inlinenoexcept |
Constructor with numerator and denominator.
n | Numerator, signed integer (basic type). |
d | Denominator, unsigned integer (basic type). |
Constructor with numerator and denominator.
n | Numerator, a lal::numeric::integer. |
d | Denominator, a lal::numeric::integer. |
|
inlinenoexcept |
Constructor with string.
s | A string. |
|
inlinenoexcept |
Copy constructor.
r | A lal::numeric::rational. |
|
noexcept |
Move constructor.
v | A lal::numeric::integer |
Move constructor with numerator and denominator.
n | Numerator, a lal::numeric::integer. |
d | Denominator, a lal::numeric::integer. |
|
noexcept |
Move constructor.
r | A lal::numeric::rational. |
|
noexcept |
Converts this rational to an integer value.
This function returns \(\left\lfloor n/d \right\rfloor\) where \(n,d\) are, respectively, the numerator and denominator.
|
inlinenoexcept |
Changes numerator and denominator.
If this rational value was \(n/d\) then after calling this method it will be \(d/n\).
|
inlinenoexcept |
Non-equality operator.
i | A lal::numeric::integer. |
|
inlinenoexcept |
Non-equality operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Non-equality operator.
i | A signed integer (basic type) number. |
Multiplication operator.
i | A lal::numeric::integer. |
Multiplication operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Multiplication operator.
i | A signed integer (basic type) number. |
Multiplication operator.
i | A lal::numeric::integer. |
Multiplication operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Multiplication operator.
i | A signed integer (basic type) number. |
Addition operator.
i | A lal::numeric::integer. |
Addition operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Addition operator.
i | A signed integer (basic type) number. |
Addition operator.
i | A lal::numeric::integer. |
Addition operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Addition operator.
i | A signed integer (basic type) number. |
Substraction operator.
i | A lal::numeric::integer. |
Substraction operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Substraction operator.
i | A signed integer (basic type) number. |
Substraction operator.
i | A lal::numeric::integer. |
Substraction operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Substraction operator.
i | A signed integer (basic type) number. |
Division operator.
i | A lal::numeric::integer. |
Division operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Division operator.
i | A signed integer (basic type) number. |
Division operator.
i | A lal::numeric::integer. |
Division operator.
r | A lal::numeric::rational. |
|
noexcept |
Division operator.
i | A signed integer (basic type) number. |
|
inlinenoexcept |
Less than operator.
i | A lal::numeric::integer. |
|
inlinenoexcept |
Less than operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Less than operator.
i | A signed integer (basic type) number. |
|
inlinenoexcept |
Less than or equal to operator.
i | A lal::numeric::integer. |
|
inlinenoexcept |
Less than or equal to operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Less than or equal to operator.
i | A signed integer (basic type) number. |
Assignment operator.
i | A lal::numeric::integer. |
Assignment operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Assignment operator.
s | A string. |
|
inlinenoexcept |
Assignment operator.
i | A signed integer (basic type) number. |
Move assignment operator.
i | A lal::numeric::integer. |
Move assignment operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Equality operator.
i | A lal::numeric::integer. |
|
inlinenoexcept |
Equality operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Equality operator.
i | A signed integer (basic type) number. |
|
inlinenoexcept |
Greater than operator.
i | A lal::numeric::integer. |
|
inlinenoexcept |
Greater than operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Greater than operator.
i | A signed integer (basic type) number. |
|
inlinenoexcept |
Greater than or equal to operator.
i | A lal::numeric::integer. |
|
inlinenoexcept |
Greater than or equal to operator.
r | A lal::numeric::rational. |
|
inlinenoexcept |
Greater than or equal to operator.
i | A signed integer (basic type) number. |
Exponentiation operator.
i | A lal::numeric::integer. |
|
noexcept |
Exponentiation operator.
i | An unsigned integer (basic type). |
Exponentiation operator.
i | A lal::numeric::integer. |
|
noexcept |
Exponentiation operator.
i | An unsigned integer (basic type). |
Overwrites the value of this rational with the value \(n/d\).
n | Numerator, a lal::numeric::integer. |
d | Denominator, a lal::numeric::integer. |
|
inlinenoexcept |
Overwrites the value of this rational with the value \(n/d\).
r | A lal::numeric::rational. |
|
inlinenoexcept |
Overwrites the value of this rational with \(n/d\).
n | Numerator, signed integer (basic type). |
d | Denominator, unsigned integer (basic type). |
|
inlinenoexcept |
Overwrites the value in the string s.
s | A string. |
|
inlinenoexcept |
Overwrites the value of this rational with \(n/d\).
n | Numerator, unsigned integer (basic type). |
d | Denominator, unsigned integer (basic type). |
|
inlinenoexcept |
Swaps the value of this rational with rational r's value.
|
inlinenoexcept |
Converts this rational to an integer value.
This function returns \(\left\lfloor n/d \right\rfloor\) where \(n,d\) are, respectively, the numerator and denominator.
Non-equality operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
|
friend |
Non-equality operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Multiplication operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
Multiplication operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Addition operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
Addition operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Substraction operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
Substraction operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Division operator.
i | A signed integer (basic type) number. |
r | Rational value. |
Less than operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
|
friend |
Less than operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Less than or equal to operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
|
friend |
Less than or equal to operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Equality operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
|
friend |
Equality operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Greater than operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
|
friend |
Greater than operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Greater than or equal to operator.
i | A lal::numeric::integer. |
r | A lal::numeric::rational. |
|
friend |
Greater than or equal to operator.
i | A signed integer (basic type) number. |
r | A lal::numeric::rational. |
Swaps two rationals.
r1 | Input rational. |
r2 | Input rational. |