From ce113b557a67dd70dbcb84c12d2daf99dc58993b Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 7 May 2024 11:51:50 -0400 Subject: [PATCH] xo-unit: + arithmetic (*,/) for scaled_unit/natural_unit pairs --- include/xo/unit/scaled_unit.hpp | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/xo/unit/scaled_unit.hpp b/include/xo/unit/scaled_unit.hpp index a0d8a6f8..ab9a8a94 100644 --- a/include/xo/unit/scaled_unit.hpp +++ b/include/xo/unit/scaled_unit.hpp @@ -153,6 +153,28 @@ namespace xo { rr.outer_scale_sq_ * x_unit.outer_scale_sq_ * y_unit.outer_scale_sq_)); } + template > + inline constexpr scaled_unit + operator* (const scaled_unit & x_unit, + const natural_unit & y_unit) + { + auto y_unit2 = detail::make_unit_rescale_result(y_unit); + + return x_unit * y_unit2; + } + + template > + inline constexpr scaled_unit + operator* (const natural_unit & x_unit, + const scaled_unit & y_unit) + { + auto x_unit2 = detail::make_unit_rescale_result(x_unit); + + return x_unit2 * y_unit; + } + template > inline constexpr scaled_unit @@ -169,6 +191,28 @@ namespace xo { * ratio::ratio(y_unit.outer_scale_factor_)), rr.outer_scale_sq_ * x_unit.outer_scale_sq_ * y_unit.outer_scale_sq_)); } + + template > + inline constexpr scaled_unit + operator/ (const scaled_unit & x_unit, + const natural_unit & y_unit) + { + auto y_unit2 = detail::make_unit_rescale_result(y_unit); + + return x_unit / y_unit2; + } + + template > + inline constexpr scaled_unit + operator/ (const natural_unit & x_unit, + const scaled_unit & y_unit) + { + auto x_unit2 = detail::make_unit_rescale_result(x_unit); + + return x_unit2 / y_unit; + } } /*namespace qty*/ } /*namespace xo*/