mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-06 17:53:23 +08:00
[PQ] Add unary minus operator
This commit is contained in:
@@ -237,6 +237,14 @@ namespace BlackMisc
|
||||
return copy;
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
PQ CPhysicalQuantity<MU, PQ>::operator -() const
|
||||
{
|
||||
PQ copy = *derived();
|
||||
copy *= -1;
|
||||
return copy;
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
bool CPhysicalQuantity<MU, PQ>::lessThan(const CPhysicalQuantity<MU, PQ> &other) const
|
||||
{
|
||||
|
||||
@@ -165,6 +165,9 @@ namespace BlackMisc
|
||||
//! Operator /
|
||||
PQ operator /(double divide) const;
|
||||
|
||||
//! Unary operator -
|
||||
PQ operator -() const;
|
||||
|
||||
//! Equal operator ==
|
||||
friend bool operator==(const CPhysicalQuantity &a, const CPhysicalQuantity &b) { return a.equals(b); }
|
||||
|
||||
|
||||
@@ -97,6 +97,12 @@ namespace BlackMiscTest
|
||||
CFrequencyUnit fu1 = CFrequencyUnit::Hz();
|
||||
QVERIFY2(fu1 != du1, "Hz must not be meter");
|
||||
|
||||
// Unary expressions
|
||||
CTemperature temp1(5, CTemperatureUnit::C());
|
||||
QVERIFY2(-temp1 == CTemperature(-5, CTemperatureUnit::C()), "Temperatures must be the same");
|
||||
CTemperature temp2(-8.7, CTemperatureUnit::K());
|
||||
QVERIFY2(-temp2 == CTemperature(8.7, CTemperatureUnit::K()), "Temperatures must be the same");
|
||||
|
||||
// null comparisons
|
||||
const CLength null(CLength::null());
|
||||
const CLength nonNull(1, CLengthUnit::m());
|
||||
|
||||
Reference in New Issue
Block a user