mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Fix floating point comparison
This commit is contained in:
@@ -40,7 +40,7 @@ namespace BlackMisc
|
||||
|
||||
int compare(double a, double b)
|
||||
{
|
||||
if (a == b) return 0;
|
||||
if (qFuzzyCompare(a, b)) return 0;
|
||||
return a < b ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace BlackMisc
|
||||
|
||||
double CMeasurementUnit::roundToEpsilon(double value) const
|
||||
{
|
||||
if (this->getEpsilon() == 0 || this->isNull()) { return value; }
|
||||
if (qFuzzyIsNull(getEpsilon()) || this->isNull()) { return value; }
|
||||
return CMathUtils::roundEpsilon(value, this->getEpsilon());
|
||||
}
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ namespace BlackMisc
|
||||
bool isEpsilon(double value) const
|
||||
{
|
||||
if (this->isNull()) return false;
|
||||
if (value == 0) return true;
|
||||
if (qFuzzyIsNull(value)) return true;
|
||||
return std::abs(value) <= this->m_data->m_epsilon;
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace BlackMisc
|
||||
template <class MU, class PQ>
|
||||
const PQ &CPhysicalQuantity<MU, PQ>::makePositive()
|
||||
{
|
||||
if (this->isNull() || m_value == 0) { return *this->derived(); }
|
||||
if (this->isNull() || qFuzzyIsNull(m_value)) { return *this->derived(); }
|
||||
if (m_value < 0) { m_value *= -1.0; }
|
||||
return *this->derived();
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace BlackMisc
|
||||
template <class MU, class PQ>
|
||||
const PQ &CPhysicalQuantity<MU, PQ>::makeNegative()
|
||||
{
|
||||
if (this->isNull() || m_value == 0) { return *this->derived(); }
|
||||
if (this->isNull() || qFuzzyIsNull(m_value)) { return *this->derived(); }
|
||||
if (m_value > 0) { m_value *= -1.0; }
|
||||
return *this->derived();
|
||||
}
|
||||
@@ -161,7 +161,7 @@ namespace BlackMisc
|
||||
template<class MU, class PQ>
|
||||
PQ CPhysicalQuantity<MU, PQ>::abs() const
|
||||
{
|
||||
if (this->isNull() || m_value == 0) { return *this->derived(); }
|
||||
if (this->isNull() || qFuzzyIsNull(m_value)) { return *this->derived(); }
|
||||
if (m_value >= 0) { return *this->derived(); }
|
||||
PQ copy(*this->derived());
|
||||
return copy.makePositive();
|
||||
|
||||
Reference in New Issue
Block a user