Rational number with numerator and denominator. More...
#include <rational.h>
Public Member Functions | |
| Rational (T n=0, T d=1) | |
| Constructs a rational number. | |
| bool | isValid () const |
| Returns true if the denominator is non-zero. | |
| Rational | operator+ (const Rational &rhs) const |
| Adds two rationals. | |
| Rational | operator- (const Rational &rhs) const |
| Subtracts two rationals. | |
| Rational | operator* (const Rational &rhs) const |
| Multiplies two rationals. | |
| Rational | operator/ (const Rational &rhs) const |
| Divides two rationals. | |
| bool | operator== (const Rational &rhs) const |
| Equality comparison. | |
| bool | operator!= (const Rational &rhs) const |
| Inequality comparison. | |
| T | numerator () const |
| Returns the numerator. | |
| T | denominator () const |
| Returns the denominator. | |
| double | toDouble () const |
| Converts to double. | |
| String | toString () const |
| Converts to a String in "num/den" format. | |
| operator String () const | |
| Implicit conversion to String. | |
Rational number with numerator and denominator.
Represents an exact fraction. Automatically simplifies on construction. A zero denominator produces an invalid Rational
| T | Underlying integer type (default: int). |
Constructs a rational number.
If d is zero the Rational is marked invalid.
| n | Numerator. |
| d | Denominator. |
Multiplies two rationals.
| rhs | Right-hand operand. |
Adds two rationals.
| rhs | Right-hand operand. |
Subtracts two rationals.
| rhs | Right-hand operand. |
Divides two rationals.
| rhs | Right-hand operand. |
Converts to double.