#include <rational.hpp>
Inheritance diagram for Arageli::rational< T >:
Public Types | |
typedef T | value_type |
Type of numerator and denominator. | |
Public Member Functions | |
rational () | |
Constructs zero. | |
rational (const char *str) | |
Initialize rational from string notation. | |
template<typename T1> | |
rational (const rational< T1 > &x) | |
Creates a copy of the some rational. | |
template<typename T1> | |
rational (const T1 &w) | |
Creates a rational from integer value w. | |
rational (const T &u, const T &v) | |
Creates the rational w/v. | |
rational (double x) | |
operator int () const | |
Convertion to int. Temporary implementation. | |
operator big_int () const | |
Convertion to big_int. Temporary implementation. | |
operator float () const | |
Converts from rational to float. | |
operator double () const | |
Converts from rational to double. | |
operator long double () const | |
Converts from rational to long double. | |
operator bool () const | |
Returns true if the rational is nonzero. | |
bool | operator! () const |
template<typename T1> | |
rational & | operator= (const rational< T1 > &x) |
Assigns numerator and denominator from x to this rational. | |
template<typename T1> | |
rational & | operator= (const T1 &x) |
Assigns this rationals with integer x. | |
rational & | operator= (double x) |
rational & | operator= (const char *s) |
const T & | numerator () const |
Access to numerator. Read-only. | |
const T & | denominator () const |
Access to denominator. Read-only. | |
T & | numerator () |
Access to numerator (non-constant). | |
T & | denominator () |
Access to denominator (non-constant). | |
rational | operator- () const |
Returns a negated rational. | |
const rational & | operator+ () const |
Return a reference to this object. For sameness only. | |
rational & | operator++ () |
rational | operator++ (int) |
rational & | operator-- () |
rational | operator-- (int) |
rational & | opposite () |
Makes opposite rational. | |
rational & | inverse () |
Inverses this rational. | |
int | sign () const |
Sign of a number. | |
bool | is_integer () const |
Returns true if this rational is integer. | |
bool | is_null () const |
Return true if this rational is zero. | |
bool | is_unit () const |
Return true if this rational is unit. | |
bool | is_opposite_unit () const |
Return true if this rational is opposite unit. | |
void | normalize () |
Reduces fraction numerator/denominator. | |
bool | is_normal () const |
Returns true if the fraction numerator/denominator is irreducible. | |
template<typename T1> | |
void | swap (rational< T1 > &x) |
Swaps two rationals without copying (if possible). |
An instance of this type is a rational number where the numerator and the denominator are both of type T.
T | a type of numerator and denominator, by default it is big_int |
Definition at line 68 of file rational.hpp.
typedef T Arageli::rational< T >::value_type |
Arageli::rational< T >::rational | ( | ) | [inline] |
Arageli::rational< T >::rational | ( | const char * | str | ) |
Initialize rational from string notation.
Arageli::rational< T >::rational | ( | const rational< T1 > & | x | ) | [inline] |
Arageli::rational< T >::rational | ( | const T1 & | w | ) | [inline] |
Creates a rational from integer value w.
After this, numerator = w, denominator = 1.
Definition at line 100 of file rational.hpp.
Arageli::rational< T >::rational | ( | const T & | u, | |
const T & | v | |||
) | [inline] |
Creates the rational w/v.
After this, numerator = w, denominator = v.
Definition at line 104 of file rational.hpp.
Arageli::rational< T >::rational | ( | double | x | ) | [inline] |
Definition at line 108 of file rational.hpp.
T& Arageli::rational< T >::denominator | ( | ) | [inline] |
const T& Arageli::rational< T >::denominator | ( | ) | const [inline] |
rational& Arageli::rational< T >::inverse | ( | ) |
Inverses this rational.
Performs swap between numerator and denominator. Requirement: denominator must not be equal to zero. Returns reference to the rational.
bool Arageli::rational< T >::is_integer | ( | ) | const [inline] |
Returns true if this rational is integer.
Returns true if denominator = 1.
Definition at line 294 of file rational.hpp.
bool Arageli::rational< T >::is_normal | ( | ) | const |
Returns true if the fraction numerator/denominator is irreducible.
After calls of all methods (except non-constant form of numerator() and denominator()) the result of is_normal() is true.
bool Arageli::rational< T >::is_null | ( | ) | const [inline] |
Return true if this rational is zero.
Return true if numerator = 0.
Definition at line 298 of file rational.hpp.
bool Arageli::rational< T >::is_opposite_unit | ( | ) | const [inline] |
Return true if this rational is opposite unit.
Return true if numerator = -1, denominator = 1.
Definition at line 306 of file rational.hpp.
bool Arageli::rational< T >::is_unit | ( | ) | const [inline] |
Return true if this rational is unit.
Return true if numerator = 1, denominator = 1.
Definition at line 302 of file rational.hpp.
void Arageli::rational< T >::normalize | ( | ) |
Reduces fraction numerator/denominator.
This method is useful if you use non-constant form of numerator() and denominator() functions and "manually" alternate their values. After call this function is_normal() always returns true.
T& Arageli::rational< T >::numerator | ( | ) | [inline] |
const T& Arageli::rational< T >::numerator | ( | ) | const [inline] |
Arageli::rational< T >::operator big_int | ( | ) | const [inline] |
Arageli::rational< T >::operator bool | ( | ) | const [inline] |
Arageli::rational< T >::operator double | ( | ) | const [inline] |
Converts from rational to double.
Just returns the result of division double(numerator)/double(denominator). WARNING! This is restricted implementation. For some values of numerator and denominator this solution doesn't work (converting to double may cause overflow even if the ration numerator/denominator in real sense is representable with available precision as double).
Definition at line 167 of file rational.hpp.
Arageli::rational< T >::operator float | ( | ) | const [inline] |
Converts from rational to float.
Just returns the result of division float(numerator)/float(denominator). WARNING! This is restricted implementation. For some values of numerator and denominator this solution doesn't work (converting to double may cause overflow even if the ration numerator/denominator in real sense is representable with available precision as double).
Definition at line 155 of file rational.hpp.
Arageli::rational< T >::operator int | ( | ) | const [inline] |
Arageli::rational< T >::operator long double | ( | ) | const [inline] |
Converts from rational to long double.
Just returns the result of division (long double)(numerator)/(long double)(denominator). WARNING! This is restricted implementation. For some values of numerator and denominator this solution doesn't work (converting to double may cause overflow even if the ration numerator/denominator in real sense is representable with available precision as double).
Definition at line 180 of file rational.hpp.
bool Arageli::rational< T >::operator! | ( | ) | const [inline] |
Definition at line 193 of file rational.hpp.
const rational& Arageli::rational< T >::operator+ | ( | ) | const [inline] |
rational Arageli::rational< T >::operator++ | ( | int | ) | [inline] |
Definition at line 261 of file rational.hpp.
rational& Arageli::rational< T >::operator++ | ( | ) | [inline] |
Definition at line 254 of file rational.hpp.
rational Arageli::rational< T >::operator- | ( | ) | const [inline] |
Returns a negated rational.
Returns a rational with numerator = - this numerator and the same denominator.
Definition at line 248 of file rational.hpp.
rational Arageli::rational< T >::operator-- | ( | int | ) | [inline] |
Definition at line 270 of file rational.hpp.
rational& Arageli::rational< T >::operator-- | ( | ) | [inline] |
Definition at line 263 of file rational.hpp.
rational& Arageli::rational< T >::operator= | ( | const char * | s | ) | [inline] |
Definition at line 229 of file rational.hpp.
rational& Arageli::rational< T >::operator= | ( | double | x | ) | [inline] |
Definition at line 225 of file rational.hpp.
rational& Arageli::rational< T >::operator= | ( | const T1 & | x | ) | [inline] |
Assigns this rationals with integer x.
After this call numerator = x, denominator = 1.
Definition at line 218 of file rational.hpp.
rational& Arageli::rational< T >::operator= | ( | const rational< T1 > & | x | ) | [inline] |
Assigns numerator and denominator from x to this rational.
Definition at line 203 of file rational.hpp.
rational& Arageli::rational< T >::opposite | ( | ) | [inline] |
Makes opposite rational.
Calls 'value_traitsopposite' for numerator of this rational. Returns reference to the rational.
Definition at line 276 of file rational.hpp.
int Arageli::rational< T >::sign | ( | ) | const |
Sign of a number.
Returns
void Arageli::rational< T >::swap | ( | rational< T1 > & | x | ) | [inline] |