Make pow()'s argument a simple (non-template) parameter

This commit is contained in:
Chip Hogg
2022-01-11 19:19:25 -05:00
parent a8d6c890a5
commit 08818ac6a8
2 changed files with 6 additions and 7 deletions

View File

@@ -128,9 +128,8 @@ constexpr bool operator==(T t, U u) {
/**
* @brief A BasePower, raised to a rational power E.
*/
template<ratio E>
constexpr auto pow(BasePower auto bp) {
bp.power = bp.power * E;
constexpr auto pow(BasePower auto bp, ratio p) {
bp.power = bp.power * p;
return bp;
}
@@ -274,7 +273,7 @@ constexpr bool operator==(magnitude<LeftBPs...>, magnitude<RightBPs...>) {
template<ratio E, BasePower auto... BPs>
constexpr auto pow(magnitude<BPs...>) {
if constexpr (E == 0) { return magnitude<>{}; }
else { return magnitude<pow<E>(BPs)...>{}; }
else { return magnitude<pow(BPs, E)...>{}; }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -98,9 +98,9 @@ TEST_CASE("base_power")
SECTION("pow() multiplies exponent")
{
CHECK(pow<0>(base_power{2}) == base_power{2, 0});
CHECK(pow<ratio{-1, 2}>(base_power{2, 3}) == base_power{2, ratio{-3, 2}});
CHECK(pow<ratio{1, 3}>(base_power<pi_base>{ratio{3, 2}}) == base_power<pi_base>{ratio{1, 2}});
CHECK(pow(base_power{2}, 0) == base_power{2, 0});
CHECK(pow(base_power{2, 3}, ratio{-1, 2}) == base_power{2, ratio{-3, 2}});
CHECK(pow(base_power<pi_base>{ratio{3, 2}}, ratio{1, 3}) == base_power<pi_base>{ratio{1, 2}});
}
}