31#ifndef ETL_RATIO_INCLUDED
32#define ETL_RATIO_INCLUDED
46 template <
intmax_t NUM,
intmax_t DEN = 1UL>
53 template <
intmax_t NUM,
intmax_t DEN>
56 template <
intmax_t NUM,
intmax_t DEN>
59 #if INT_MAX > INT32_MAX
67 #if (INT_MAX >= INT32_MAX)
72 #if (INT_MAX >= INT16_MAX)
81 #if (INT_MAX >= INT32_MAX)
86 #if INT_MAX > INT32_MAX
107 template <
typename T, T A, T B,
bool = (B == 0)>
111 template <
typename T, T A, T B>
118 template <
typename T, T A, T B>
121 static constexpr T value = (
A < 0) ? -
A :
A;
125 template <
typename T, T A, T B>
137 template<
typename R1>
142 static ETL_CONSTEXPR11
intmax_t gcd = etl::private_ratio::ratio_gcd<intmax_t, R1::num, R1::den>::value;
146 using type =
ratio<R1::num / gcd, R1::den / gcd>;
149 template<
typename R1,
typename R2>
154 static ETL_CONSTEXPR11
intmax_t lcm = etl::private_ratio::ratio_lcm<intmax_t, R1::den, R2::den>::value;
158 using type =
typename ratio_reduce<
ratio<R1::num * lcm / R1::den + R2::num * lcm / R2::den, lcm>>::type;
161 template<
typename R1,
typename R2>
168 template<
typename R1,
typename R2>
172 static ETL_CONSTEXPR11
intmax_t gcd1 = etl::private_ratio::ratio_gcd<intmax_t, R1::num, R2::den>::value;
173 static ETL_CONSTEXPR11
intmax_t gcd2 = etl::private_ratio::ratio_gcd<intmax_t, R2::num, R1::den>::value;
179 template<
typename R1,
typename R2>
187 template<
typename R1,
typename R2>
188 using ratio_add =
typename private_ratio::ratio_add<R1, R2>::type;
190 template<
typename R1,
typename R2>
191 using ratio_subtract =
typename private_ratio::ratio_subtract<R1, R2>::type;
193 template<
typename R1,
typename R2>
194 using ratio_multiply =
typename private_ratio::ratio_multiply<R1, R2>::type;
196 template<
typename R1,
typename R2>
197 using ratio_divide =
typename private_ratio::ratio_divide<R1, R2>::type;
199 template<
typename R1,
typename R2>
204 template<
typename R1,
typename R2>
209 template<
typename R1,
typename R2>
214 template<typename R1, typename R2>
215 struct ratio_less_equal : etl::integral_constant<bool, (R1::num * R2::den <= R2::num * R1::den)>
219 template<typename R1, typename R2>
220 struct ratio_greater : etl::integral_constant<bool, (R1::num * R2::den > R2::num * R1::den)>
224 template<typename R1, typename R2>
225 struct ratio_greater_equal: etl::integral_constant<bool, (R1::num * R2::den >= R2::num * R1::den)>
230 template<
typename R1,
typename R2>
231 ETL_CONSTEXPR14
bool ratio_equal_v = ratio_equal<R1, R2>::value;
233 template<
typename R1,
typename R2>
234 ETL_CONSTEXPR14
bool ratio_not_equal_v = ratio_not_equal<R1, R2>::value;
236 template<
typename R1,
typename R2>
237 ETL_CONSTEXPR14
bool ratio_less_v = ratio_less<R1, R2>::value;
239 template<
typename R1,
typename R2>
240 ETL_CONSTEXPR14
bool ratio_less_equal_v = ratio_less_equal<R1, R2>::value;
242 template<
typename R1,
typename R2>
243 ETL_CONSTEXPR14
bool ratio_greater_v = ratio_greater<R1, R2>::value;
245 template<
typename R1,
typename R2>
246 ETL_CONSTEXPR14
bool ratio_greater_equal_v = ratio_greater_equal<R1, R2>::value;
integral_constant
Definition type_traits_generator.h:827
bitset_ext
Definition absolute.h:38
ratio< 355, 113 > ratio_pi
An approximation of PI to 6 digits.
Definition ratio.h:95
ratio< 326, 120 > ratio_e
An approximation of e.
Definition ratio.h:101
ratio< 239, 169 > ratio_root2
An approximation of root 2.
Definition ratio.h:98
pair holds two objects of arbitrary type
Definition utility.h:164