diff --git a/include/xo/unit/Quantity.hpp b/include/xo/unit/Quantity.hpp index c46552ea..dc846fda 100644 --- a/include/xo/unit/Quantity.hpp +++ b/include/xo/unit/Quantity.hpp @@ -195,6 +195,10 @@ namespace xo { return x.scale() <=> y2.scale(); } + Quantity operator-() const { + return Quantity(-scale_, unit_); + } + /* also works with Quantity2 = double, int, .. */ template Quantity & operator*= (const Quantity2 & x) { diff --git a/utest/Quantity.test.cpp b/utest/Quantity.test.cpp index 15d52196..01ee661c 100644 --- a/utest/Quantity.test.cpp +++ b/utest/Quantity.test.cpp @@ -340,6 +340,10 @@ namespace xo { auto q1_minus_q2 = q1 - q2; REQUIRE(q1_minus_q2.unit() == q1.unit()); REQUIRE(q1_minus_q2.scale() == Approx(1.0 - k2).epsilon(1.0e-6)); + + auto q1_neg = -q1; + REQUIRE(q1_neg.unit() == q1.unit()); + REQUIRE(q1_neg.scale() == -q1.scale()); } } }