From 14258c97fd530ec0b67dcc545c43813dc728bdce Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 1 Jun 2023 08:47:55 +0200 Subject: [PATCH] refactor: `magnitude::pow()` now takes two `int`s rather than a `ratio` (consistent with the rest of library) --- src/core/include/mp-units/bits/magnitude.h | 12 ++++++------ src/core/include/mp-units/unit.h | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/include/mp-units/bits/magnitude.h b/src/core/include/mp-units/bits/magnitude.h index 2d05ded0..6f9e238a 100644 --- a/src/core/include/mp-units/bits/magnitude.h +++ b/src/core/include/mp-units/bits/magnitude.h @@ -517,26 +517,26 @@ template //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Magnitude rational powers implementation. -template +template [[nodiscard]] consteval auto pow(magnitude) { - if constexpr (E.num == 0) { + if constexpr (Num == 0) { return magnitude<>{}; } else { - return magnitude()...>{}; + return magnitude()...>{}; } } template [[nodiscard]] consteval auto sqrt(magnitude m) { - return pow(m); + return pow<1, 2>(m); } template [[nodiscard]] consteval auto cbrt(magnitude m) { - return pow(m); + return pow<1, 3>(m); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -781,7 +781,7 @@ inline constexpr Magnitude auto mag = detail::prime_factorization_v / det */ template requires detail::gt_zero -inline constexpr Magnitude auto mag_power = pow(mag); +inline constexpr Magnitude auto mag_power = pow(mag); namespace detail { diff --git a/src/core/include/mp-units/unit.h b/src/core/include/mp-units/unit.h index 1906ab3f..f3d21baa 100644 --- a/src/core/include/mp-units/unit.h +++ b/src/core/include/mp-units/unit.h @@ -372,10 +372,9 @@ template if constexpr (requires { typename decltype(base.reference_unit)::_num_; }) { auto num = get_canonical_unit_impl(power{}, typename decltype(base.reference_unit)::_num_{}); auto den = get_canonical_unit_impl(power{}, typename decltype(base.reference_unit)::_den_{}); - return canonical_unit{pow::exponent>(base.mag) * num.mag / den.mag, - num.reference_unit / den.reference_unit}; + return canonical_unit{pow(base.mag) * num.mag / den.mag, num.reference_unit / den.reference_unit}; } else { - return canonical_unit{pow::exponent>(base.mag), + return canonical_unit{pow(base.mag), derived_unit, Num, Den...>>{}}; } }