MUSX Document Model
|
A class to represent fractions with integer m_numerator and m_denominator, automatically reduced to simplest form. More...
#include <Fraction.h>
Public Member Functions | |
Fraction (int num=0, int den=1) | |
Constructs a Fraction object. | |
int | numerator () const |
Gets the m_numerator of the fraction. | |
int | denominator () const |
Gets the m_denominator of the fraction. | |
int | quotient () const |
Returns the integer (whole number) part of the fraction. | |
Fraction | remainder () const |
Returns the fractional part of the fraction. | |
dom::Edu | calcEduDuration () const |
Calculates duration as a fraction of a whole note. | |
Fraction | operator+ (const Fraction &other) const |
Adds two fractions. | |
Fraction | operator- (const Fraction &other) const |
Subtracts one fraction from another. | |
Fraction | operator* (const Fraction &other) const |
Multiplies two fractions. | |
Fraction | operator/ (const Fraction &other) const |
Divides one fraction by another. | |
Fraction & | operator+= (const Fraction &other) |
Compound addition assignment operator. | |
Fraction & | operator-= (const Fraction &other) |
Compound subtraction assignment operator. | |
Fraction & | operator*= (const Fraction &other) |
Compound multiplication assignment operator. | |
Fraction & | operator/= (const Fraction &other) |
Compound division assignment operator. | |
bool | operator== (const Fraction &other) const |
Equality comparison operator. | |
bool | operator!= (const Fraction &other) const |
Inequality comparison operator. | |
bool | operator< (const Fraction &other) const |
Less-than comparison operator. | |
bool | operator<= (const Fraction &other) const |
Less-than-or-equal-to comparison operator. | |
bool | operator> (const Fraction &other) const |
Greater-than comparison operator. | |
bool | operator>= (const Fraction &other) const |
Greater-than-or-equal-to comparison operator. | |
operator bool () const | |
Checks if the fraction is nonzero. | |
Static Public Member Functions | |
static Fraction | fromEdu (int edu) |
Constructs a Fraction from edu. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Fraction &frac) |
Stream output operator. | |
std::istream & | operator>> (std::istream &is, Fraction &frac) |
Stream input operator. | |
A class to represent fractions with integer m_numerator and m_denominator, automatically reduced to simplest form.
|
inline |
Constructs a Fraction object.
num | The m_numerator of the fraction. |
den | The m_denominator of the fraction. Defaults to 1. |
std::invalid_argument | if the m_denominator is zero. |
|
inline |
Gets the m_denominator of the fraction.
|
static |
Constructs a Fraction from edu.
edu |
|
inline |
Gets the m_numerator of the fraction.
|
inlineexplicit |
Checks if the fraction is nonzero.
|
inline |
Inequality comparison operator.
other | The other fraction to compare. |
Multiplies two fractions.
other | The other fraction to multiply. |
Compound multiplication assignment operator.
other | The other fraction to multiply. |
Adds two fractions.
other | The other fraction to add. |
Compound addition assignment operator.
other | The other fraction to add. |
Subtracts one fraction from another.
other | The other fraction to subtract. |
Compound subtraction assignment operator.
other | The other fraction to subtract. |
Divides one fraction by another.
other | The other fraction to divide by. |
std::invalid_argument | if attempting to divide by a fraction with a zero m_numerator. |
Compound division assignment operator.
other | The other fraction to divide by. |
std::invalid_argument | if attempting to divide by a fraction with a zero m_numerator. |
|
inline |
Less-than comparison operator.
other | The other fraction to compare. |
|
inline |
Less-than-or-equal-to comparison operator.
other | The other fraction to compare. |
|
inline |
Equality comparison operator.
other | The other fraction to compare. |
|
inline |
Greater-than comparison operator.
other | The other fraction to compare. |
|
inline |
Greater-than-or-equal-to comparison operator.
other | The other fraction to compare. |
|
inline |
Returns the integer (whole number) part of the fraction.
|
inline |
Returns the fractional part of the fraction.
|
friend |
Stream output operator.
os | The output stream. |
frac | The fraction to output. |
|
friend |
Stream input operator.
is | The input stream. |
frac | The fraction to populate. |
std::invalid_argument | if the input format is invalid or the m_denominator is zero. |