Skip to content

Commit 89801c9

Browse files
committed
av::Rational: added num/Rational and Rational/num division
1 parent aadb6c6 commit 89801c9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/rational.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <utility>
44
#include <iostream>
55
#include <memory>
6+
#include <type_traits>
67

78
#if __cplusplus > 201703L
89
#include <compare>
@@ -100,6 +101,20 @@ class Rational
100101
};
101102

102103

104+
template<typename T>
105+
auto operator/ (T num, Rational value) ->
106+
std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>, Rational>
107+
{
108+
return Rational{num, 1} / value;
109+
}
110+
111+
template<typename T>
112+
auto operator/ (Rational value, T num) ->
113+
std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>, Rational>
114+
{
115+
return value / Rational{num, 1};
116+
}
117+
103118
inline std::ostream& operator<< (std::ostream &stream, const Rational &value)
104119
{
105120
stream << value.getNumerator() << '/' << value.getDenominator();

0 commit comments

Comments
 (0)