Skip to content

Commit

Permalink
xo-unit: + unary Quantity.operator-
Browse files Browse the repository at this point in the history
  • Loading branch information
Rconybea committed Apr 27, 2024
1 parent e1fee23 commit 8d1bdf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/xo/unit/Quantity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Quantity2>
Quantity & operator*= (const Quantity2 & x) {
Expand Down
4 changes: 4 additions & 0 deletions utest/Quantity.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down

0 comments on commit 8d1bdf5

Please sign in to comment.