common_ratio refactored

This commit is contained in:
Mateusz Pusz
2019-05-28 15:01:50 +02:00
parent c43871578e
commit 7bcc5c7b0b
3 changed files with 16 additions and 13 deletions
+11 -8
View File
@@ -69,16 +69,19 @@ namespace units {
concept bool Ratio = detail::is_ratio<T>;
// common_ratio
namespace detail {
// todo: simplified
template<Ratio R1, Ratio R2>
struct common_ratio {
using gcd_num = static_gcd<R1::num, R2::num>;
using gcd_den = static_gcd<R1::den, R2::den>;
using type = std::ratio<gcd_num::value, (R1::den / gcd_den::value) * R2::den>;
};
// todo: simplified
template<typename R1, typename R2>
struct common_ratio_impl {
using gcd_num = static_gcd<R1::num, R2::num>;
using gcd_den = static_gcd<R1::den, R2::den>;
using type = std::ratio<gcd_num::value, (R1::den / gcd_den::value) * R2::den>;
};
}
template<Ratio R1, Ratio R2>
using common_ratio_t = common_ratio<R1, R2>::type;
using common_ratio = detail::common_ratio_impl<R1, R2>::type;
} // namespace units