mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
[PQ] Add unary minus operator
This commit is contained in:
@@ -237,6 +237,14 @@ namespace BlackMisc
|
|||||||
return copy;
|
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>
|
template <class MU, class PQ>
|
||||||
bool CPhysicalQuantity<MU, PQ>::lessThan(const CPhysicalQuantity<MU, PQ> &other) const
|
bool CPhysicalQuantity<MU, PQ>::lessThan(const CPhysicalQuantity<MU, PQ> &other) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ namespace BlackMisc
|
|||||||
//! Operator /
|
//! Operator /
|
||||||
PQ operator /(double divide) const;
|
PQ operator /(double divide) const;
|
||||||
|
|
||||||
|
//! Unary operator -
|
||||||
|
PQ operator -() const;
|
||||||
|
|
||||||
//! Equal operator ==
|
//! Equal operator ==
|
||||||
friend bool operator==(const CPhysicalQuantity &a, const CPhysicalQuantity &b) { return a.equals(b); }
|
friend bool operator==(const CPhysicalQuantity &a, const CPhysicalQuantity &b) { return a.equals(b); }
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,12 @@ namespace BlackMiscTest
|
|||||||
CFrequencyUnit fu1 = CFrequencyUnit::Hz();
|
CFrequencyUnit fu1 = CFrequencyUnit::Hz();
|
||||||
QVERIFY2(fu1 != du1, "Hz must not be meter");
|
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
|
// null comparisons
|
||||||
const CLength null(CLength::null());
|
const CLength null(CLength::null());
|
||||||
const CLength nonNull(1, CLengthUnit::m());
|
const CLength nonNull(1, CLengthUnit::m());
|
||||||
|
|||||||
Reference in New Issue
Block a user