From 5a7f58be41f5620b382c3a108f4b983417a38ae8 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 20 Oct 2022 14:05:20 +0200 Subject: [PATCH] fix: Added a special case for multiplication of opposite magnitude exponents --- src/core/include/units/magnitude.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/include/units/magnitude.h b/src/core/include/units/magnitude.h index c45c40a9..e4aff28b 100644 --- a/src/core/include/units/magnitude.h +++ b/src/core/include/units/magnitude.h @@ -588,13 +588,17 @@ constexpr Magnitude auto operator*(magnitude, magnitude) constexpr auto partial_product = magnitude{} * magnitude{}; if constexpr (is_same_v) { - // Make a new power_v with the common base of H1 and H2, whose power is their powers' sum. - constexpr auto new_head = power_v_or_T(); - - if constexpr (get_exponent(new_head) == 0) { - return partial_product; + if constexpr (get_exponent(H1) + get_exponent(H2) == 0) { + return magnitude<1>{}; } else { - return magnitude{} * partial_product; + // Make a new power_v with the common base of H1 and H2, whose power is their powers' sum. + constexpr auto new_head = power_v_or_T(); + + if constexpr (get_exponent(new_head) == 0) { + return partial_product; + } else { + return magnitude{} * partial_product; + } } } else if constexpr (is_named_magnitude) { return magnitude

{} * (magnitude{} * magnitude{});