diff --git a/src/Fraction.h b/src/Fraction.h index e021dff9..fd1cca87 100644 --- a/src/Fraction.h +++ b/src/Fraction.h @@ -64,8 +64,44 @@ public: /// Return the reciprocal as a Fraction Fraction Reciprocal() const; + + // Multiplication and division + + /// Multiply two Fraction objects together + openshot::Fraction operator*(openshot::Fraction other) { + return openshot::Fraction(num * other.num, den * other.den); + } + + /// Divide a Fraction by another Fraction + openshot::Fraction operator/(openshot::Fraction other) { + return *this * other.Reciprocal(); + } + + /// Multiplication in the form (openshot_Fraction * numeric_value) + template + numT operator*(const numT& other) const { + return static_cast(ToDouble() * other); + } + + /// Division in the form (openshot_Fraction / numeric_value) + template + numT operator/(const numT& other) const { + return static_cast(ToDouble() / other); + } }; +/// Multiplication in the form (numeric_value * openshot_Fraction) +template +numT operator*(const numT& left, const openshot::Fraction& right) { + return static_cast(left * right.ToDouble()); +} + +/// Division in the form (numeric_value / openshot_Fraction) +template +numT operator/(const numT& left, const openshot::Fraction& right) { + return static_cast(left / right.ToDouble()); +} + // Stream output operator for openshot::Fraction template std::basic_ostream&