|
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. | |
| constexpr int | numerator () const |
| Gets the m_numerator of the fraction. | |
| constexpr int | denominator () const |
| Gets the m_denominator of the fraction. | |
| constexpr int | quotient () const |
| Returns the integer (whole number) part of the fraction. | |
| Fraction | remainder () const |
| Returns the fractional part of the fraction. | |
| Fraction | reciprocal () const |
| Returns the reciprocal fraction. | |
| constexpr dom::Edu | calcEduDuration () const |
| Calculates duration as a fraction of a whole note. | |
| constexpr double | toDouble () const |
| Converts the fraction to floating point double. | |
| 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. | |
| constexpr bool | operator== (const Fraction &other) const |
| Equality comparison operator. (This depends on the fact that instances of Fraction are always reduced in the constructor.) | |
| constexpr bool | operator!= (const Fraction &other) const |
| Inequality comparison operator. | |
| constexpr bool | operator< (const Fraction &other) const |
| Less-than comparison operator. | |
| constexpr bool | operator<= (const Fraction &other) const |
| Less-than-or-equal-to comparison operator. | |
| constexpr bool | operator> (const Fraction &other) const |
| Greater-than comparison operator. | |
| constexpr bool | operator>= (const Fraction &other) const |
| Greater-than-or-equal-to comparison operator. | |
| constexpr | operator bool () const |
| Checks if the fraction is nonzero. | |
Static Public Member Functions | |
| static Fraction | fromEdu (dom::Edu edu) |
| Constructs a Fraction from edu. | |
| static Fraction | fromPercent (int percent) |
| Constructs a Fraction from a percent (where 100 is 100%) | |
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 |
|
inlineconstexpr |
Gets the m_denominator of the fraction.
|
inlinestatic |
|
inlineconstexpr |
Gets the m_numerator of the fraction.
|
inlineexplicitconstexpr |
Checks if the fraction is nonzero.
|
inlineconstexpr |
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. |
|
inlineconstexpr |
Less-than comparison operator.
| other | The other fraction to compare. |
|
inlineconstexpr |
Less-than-or-equal-to comparison operator.
| other | The other fraction to compare. |
|
inlineconstexpr |
Equality comparison operator. (This depends on the fact that instances of Fraction are always reduced in the constructor.)
| other | The other fraction to compare. |
|
inlineconstexpr |
Greater-than comparison operator.
| other | The other fraction to compare. |
|
inlineconstexpr |
Greater-than-or-equal-to comparison operator.
| other | The other fraction to compare. |
|
inlineconstexpr |
Returns the integer (whole number) part of the fraction.
|
inline |
Returns the reciprocal 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. |