diff --git a/src/blackmisc/comparefunctions.cpp b/src/blackmisc/comparefunctions.cpp index 1a9f4718f..ecae024f8 100644 --- a/src/blackmisc/comparefunctions.cpp +++ b/src/blackmisc/comparefunctions.cpp @@ -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; } diff --git a/src/blackmisc/pq/measurementunit.cpp b/src/blackmisc/pq/measurementunit.cpp index cc6102417..aa671baef 100644 --- a/src/blackmisc/pq/measurementunit.cpp +++ b/src/blackmisc/pq/measurementunit.cpp @@ -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()); } diff --git a/src/blackmisc/pq/measurementunit.h b/src/blackmisc/pq/measurementunit.h index ba6f9cfbc..a54885819 100644 --- a/src/blackmisc/pq/measurementunit.h +++ b/src/blackmisc/pq/measurementunit.h @@ -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; } diff --git a/src/blackmisc/pq/physicalquantity.cpp b/src/blackmisc/pq/physicalquantity.cpp index 8737a92e0..0d9ac6326 100644 --- a/src/blackmisc/pq/physicalquantity.cpp +++ b/src/blackmisc/pq/physicalquantity.cpp @@ -145,7 +145,7 @@ namespace BlackMisc template const PQ &CPhysicalQuantity::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 const PQ &CPhysicalQuantity::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 PQ CPhysicalQuantity::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();