29struct ReducedToLowestFormHelper
31 static constexpr auto gcd = std::gcd (Ratio::num, Ratio::den);
33 using Type = std::ratio<Ratio::num / gcd, Ratio::den / gcd>;
37template <is::stdRatio Ratio>
38using ReducedToLowestForm =
typename ReducedToLowestFormHelper<Ratio>::Type;
45template <is::stdRatio Ratio, is::
intNumber T>
46constexpr auto multiplyBy (T valueToScale)
48 using R = ReducedToLowestForm<Ratio>;
49 using IntType = std::make_signed_t<T>;
50 using DivType =
decltype (std::div (std::declval<IntType>(), std::declval<IntType>()));
51 auto res = IntType (valueToScale) * IntType (R::num);
53 if (std::is_constant_evaluated())
56 d.quot = res / IntType (R::den);
57 d.rem = res % IntType (R::den);
61 return std::div (res, IntType (R::den));
65template <is::stdRatio Ratio, is::realOrComplexFloatNumber T>
66constexpr T multiplyBy (T valueToScale)
68 using R = ReducedToLowestForm<Ratio>;
69 valueToScale *= T (R::num);
70 return valueToScale / T (R::den);
78template <is::stdRatio Ratio, is::
intNumber T>
79constexpr auto expectNoRemainderMultiplyBy (T valueToScale)
81 auto res = multiplyBy<Ratio> (valueToScale);
82 VCTR_ASSERT (res.rem == 0);