diff --git a/src/include/units/math.h b/src/include/units/math.h index 4a55ba1a..ae2e3397 100644 --- a/src/include/units/math.h +++ b/src/include/units/math.h @@ -38,15 +38,16 @@ namespace units { * @param q Quantity being the base of the operation * @return Quantity The result of computation */ -template +template requires(N != 0) -inline Quantity AUTO pow(const quantity& q) noexcept +inline Quantity AUTO pow(const Q& q) noexcept requires requires { std::pow(q.count(), N); } { - using dim = dimension_pow; - using ratio = ratio_pow; + using dim = dimension_pow; + using ratio = ratio_pow; using unit = downcast_unit; - return quantity(static_cast(std::pow(q.count(), N))); + using rep = Q::rep; + return quantity(static_cast(std::pow(q.count(), N))); } /** @@ -54,9 +55,9 @@ inline Quantity AUTO pow(const quantity& q) noexcept * * @return Rep A scalar value of @c 1. */ -template +template requires(N == 0) -inline Rep pow(const quantity&) noexcept +inline Q::rep pow(const Q&) noexcept { return 1; } @@ -69,14 +70,15 @@ inline Rep pow(const quantity&) noexcept * @param q Quantity being the base of the operation * @return Quantity The result of computation */ -template -inline Quantity AUTO sqrt(const quantity& q) noexcept +template +inline Quantity AUTO sqrt(const Q& q) noexcept requires requires { std::sqrt(q.count()); } { - using dim = dimension_sqrt; - using ratio = ratio_sqrt; + using dim = dimension_sqrt; + using ratio = ratio_sqrt; using unit = downcast_unit; - return quantity(static_cast(std::sqrt(q.count()))); + using rep = Q::rep; + return quantity(static_cast(std::sqrt(q.count()))); } /** @@ -85,11 +87,11 @@ inline Quantity AUTO sqrt(const quantity& q) noexcept * @param q Quantity being the base of the operation * @return Quantity The absolute value of a provided quantity */ -template -constexpr Quantity AUTO abs(const quantity& q) noexcept +template +constexpr Quantity AUTO abs(const Q& q) noexcept requires requires { std::abs(q.count()); } { - return quantity(std::abs(q.count())); + return Q(std::abs(q.count())); } /**