From c79a76ab8f16fd40cb45aceca3cdc585cf817aec Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 13 Jun 2023 09:17:32 +0300 Subject: [PATCH] fix: `pow`, `sqrt`, and `cbrt` fixed for quantities --- src/utility/include/mp-units/math.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/utility/include/mp-units/math.h b/src/utility/include/mp-units/math.h index 802377dc..3c68244f 100644 --- a/src/utility/include/mp-units/math.h +++ b/src/utility/include/mp-units/math.h @@ -51,17 +51,17 @@ namespace mp_units { */ template requires detail::non_zero -[[nodiscard]] constexpr auto pow(const Q& q) noexcept +[[nodiscard]] constexpr Quantity auto pow(const Q& q) noexcept requires requires { pow(q.number(), 1.0); } || requires { std::pow(q.number(), 1.0); } { using rep = TYPENAME Q::rep; if constexpr (Num == 0) { - return rep(1); + return make_quantity(Q::reference)>(rep(1)); } else if constexpr (ratio{Num, Den} == 1) { return q; } else { using std::pow; - return make_quantity(Q::quantity_spec), pow(Q::unit)>{}>( + return make_quantity(Q::reference)>( static_cast(pow(q.number(), static_cast(Num) / static_cast(Den)))); } } @@ -80,8 +80,7 @@ template { using rep = TYPENAME Q::rep; using std::sqrt; - return make_quantity(Q::quantity_spec), pow<1, 2>(Q::unit)>{}>( - static_cast(sqrt(q.number()))); + return make_quantity(static_cast(sqrt(q.number()))); } /** @@ -98,8 +97,7 @@ template { using rep = TYPENAME Q::rep; using std::cbrt; - return make_quantity(Q::quantity_spec), pow<1, 3>(Q::unit)>{}>( - static_cast(cbrt(q.number()))); + return make_quantity(static_cast(cbrt(q.number()))); } /**