[FSD] Use qFuzzyCompare for double comparison

fixes "warning: comparing floating point with == or != is unsafe"
This commit is contained in:
Klaus Basan
2020-03-12 19:52:05 +01:00
committed by Mat Sutcliffe
parent 84ae160b14
commit 5decc7d917
3 changed files with 16 additions and 16 deletions

View File

@@ -36,12 +36,12 @@ namespace BlackCore
static QString pdu() { return "#SB"; }
//! Properties @{
double m_latitude = 0.0;
double m_latitude = 0.0;
double m_longitude = 0.0;
int m_altitudeTrue = 0.0;
int m_groundSpeed = 0.0;
int m_groundSpeed = 0.0;
double m_pitch = 0.0;
double m_bank = 0.0;
double m_bank = 0.0;
double m_heading = 0.0;
bool m_onGround = false;
//! @}
@@ -55,12 +55,12 @@ namespace BlackCore
{
return lhs.sender() == rhs.sender() &&
lhs.receiver() == rhs.receiver() &&
lhs.m_latitude == rhs.m_latitude &&
lhs.m_longitude == rhs.m_longitude &&
qFuzzyCompare(lhs.m_latitude, rhs.m_latitude) &&
qFuzzyCompare(lhs.m_longitude, rhs.m_longitude) &&
lhs.m_altitudeTrue == rhs.m_altitudeTrue &&
lhs.m_pitch == rhs.m_pitch &&
lhs.m_bank == rhs.m_bank &&
lhs.m_heading == rhs.m_heading &&
qFuzzyCompare(lhs.m_pitch, rhs.m_pitch) &&
qFuzzyCompare(lhs.m_bank, rhs.m_bank) &&
qFuzzyCompare(lhs.m_heading, rhs.m_heading) &&
lhs.m_onGround == rhs.m_onGround;
}

View File

@@ -48,7 +48,7 @@ namespace BlackCore
tokens.push_back(m_sender);
tokens.push_back(QString::number(m_transponderCode));
tokens.push_back(toQString(m_rating));
tokens.push_back(QString::number(m_latitude, 'f', 5));
tokens.push_back(QString::number(m_latitude, 'f', 5));
tokens.push_back(QString::number(m_longitude, 'f', 5));
tokens.push_back(QString::number(m_altitudeTrue));
tokens.push_back(QString::number(m_groundSpeed));
@@ -66,7 +66,7 @@ namespace BlackCore
}
double pitch = 0.0;
double bank = 0.0;
double bank = 0.0;
double heading = 0.0;
bool onGround = false;
unpackPBH(tokens[8].toUInt(), pitch, bank, heading, onGround);

View File

@@ -63,14 +63,14 @@ namespace BlackCore
lhs.m_transponderMode == rhs.m_transponderMode &&
lhs.m_transponderCode == rhs.m_transponderCode &&
lhs.m_rating == rhs.m_rating &&
lhs.m_latitude == rhs.m_latitude &&
lhs.m_longitude == rhs.m_longitude &&
qFuzzyCompare(lhs.m_latitude, rhs.m_latitude) &&
qFuzzyCompare(lhs.m_longitude, rhs.m_longitude) &&
lhs.m_altitudeTrue == rhs.m_altitudeTrue &&
lhs.m_altitudePressure == rhs.m_altitudePressure &&
lhs.m_groundSpeed == rhs.m_groundSpeed &&
lhs.m_pitch == rhs.m_pitch &&
lhs.m_bank == rhs.m_bank &&
lhs.m_heading == rhs.m_heading &&
lhs.m_groundSpeed == rhs.m_groundSpeed &&
qFuzzyCompare(lhs.m_pitch, rhs.m_pitch) &&
qFuzzyCompare(lhs.m_bank, rhs.m_bank) &&
qFuzzyCompare(lhs.m_heading, rhs.m_heading) &&
lhs.m_onGround == rhs.m_onGround;
}