31#ifndef ETL_RATIO_INCLUDED
32#define ETL_RATIO_INCLUDED
35#include "static_assert.h"
51 template <
intmax_t Num,
intmax_t Den = 1UL>
54 ETL_STATIC_ASSERT(
Num != 0,
"Numerator cannot be zero");
55 ETL_STATIC_ASSERT(
Den != 0,
"Denominator cannot be zero");
63 template <
intmax_t Num,
intmax_t Den>
66 template <
intmax_t Num,
intmax_t Den>
73 template <
typename TRatio1,
typename TRatio2>
74 using ratio_add =
etl::ratio<(TRatio1::num * TRatio2::den) + (TRatio2::num * TRatio1::den), TRatio1::den * TRatio2::den>;
79 template <
typename TRatio1,
typename TRatio2>
80 using ratio_subtract =
etl::ratio<(TRatio1::num * TRatio2::den) - (TRatio2::num * TRatio1::den), TRatio1::den * TRatio2::den>;
85 template <
typename TRatio1,
typename TRatio2>
91 template <
typename TRatio1,
typename TRatio2>
98 template <
typename TRatio1,
typename TRatio2>
106 template <
typename TRatio1,
typename TRatio2>
114 template <
typename TRatio1,
typename TRatio2>
122 template <typename TRatio1, typename TRatio2>
123 struct ratio_less_equal : etl::bool_constant<!etl::ratio_less<TRatio2, TRatio1>::value>
130 template <typename TRatio1, typename TRatio2>
131 struct ratio_greater : etl::bool_constant<etl::ratio_less<TRatio2, TRatio1>::value>
138 template <typename TRatio1, typename TRatio2>
139 struct ratio_greater_equal : etl::bool_constant<!etl::ratio_less<TRatio1, TRatio2>::value>
144 template<typename R1, typename R2>
145 inline constexpr bool ratio_equal_v = ratio_equal<R1, R2>::value;
147 template<typename R1, typename R2>
148 inline constexpr bool ratio_not_equal_v = ratio_not_equal<R1, R2>::value;
150 template<typename R1, typename R2>
151 inline constexpr bool ratio_less_v = ratio_less<R1, R2>::value;
153 template<typename R1, typename R2>
154 inline constexpr bool ratio_less_equal_v = ratio_less_equal<R1, R2>::value;
156 template<typename R1, typename R2>
157 inline constexpr bool ratio_greater_v = ratio_greater<R1, R2>::value;
159 template<typename R1, typename R2>
160 inline constexpr bool ratio_greater_equal_v = ratio_greater_equal<R1, R2>::value;
172 #if (INT_MAX >= INT32_MAX)
177 #if (INT_MAX >= INT16_MAX)
186 #if (INT_MAX >= INT32_MAX)
191 #if INT_MAX > INT32_MAX
213 template <
typename T, T A, T B,
bool = (B == 0)>
217 template <
typename T, T A, T B>
220 static constexpr T value = ratio_gcd<T, B, A % B>::value;
224 template <
typename T, T A, T B>
227 static constexpr T value = (A < 0) ? -A : A;
231 template <
typename T, T A, T B>
236 static constexpr T product = ((A * B) < 0) ? -(A * B) : A * B;
240 static constexpr T value = product / ratio_gcd<T, A, B>::value;
243 template<
typename R1>
248 static ETL_CONSTEXPR11 intmax_t gcd = etl::private_ratio::ratio_gcd<intmax_t, R1::num, R1::den>::value;
252 using type = ratio<R1::num / gcd, R1::den / gcd>;
255 template<
typename R1,
typename R2>
260 static ETL_CONSTEXPR11 intmax_t lcm = etl::private_ratio::ratio_lcm<intmax_t, R1::den, R2::den>::value;
264 using type =
typename ratio_reduce<ratio<R1::num * lcm / R1::den + R2::num * lcm / R2::den, lcm>>::type;
267 template<
typename R1,
typename R2>
271 using type =
typename ratio_add<R1, ratio<-R2::num, R2::den>>::type;
274 template<
typename R1,
typename R2>
278 static ETL_CONSTEXPR11 intmax_t gcd1 = etl::private_ratio::ratio_gcd<intmax_t, R1::num, R2::den>::value;
279 static ETL_CONSTEXPR11 intmax_t gcd2 = etl::private_ratio::ratio_gcd<intmax_t, R2::num, R1::den>::value;
282 using type = ratio<(R1::num / gcd1) * (R2::num / gcd2), (R1::den / gcd2) * (R2::den / gcd1)>;
285 template<
typename R1,
typename R2>
289 using type =
typename ratio_multiply<R1, ratio<R2::den, R2::num>>::type;
bitset_ext
Definition absolute.h:38
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
Definition type_traits_generator.h:888
ratio_equal
Definition ratio.h:100
ratio_not_equal
Definition ratio.h:108
ratio
Definition ratio.h:53