Browse Source

Add QGC::fuzzyCompare which works in all cases

QGC4.4
DonLakeFlyer 5 years ago
parent
commit
d6e0e34220
  1. 16
      src/QGC.cc
  2. 11
      src/QGC.h

16
src/QGC.cc

@ -9,9 +9,12 @@ @@ -9,9 +9,12 @@
#include "QGC.h"
#include <qmath.h>
#include <float.h>
#include <QtGlobal>
namespace QGC
{
@ -137,4 +140,17 @@ quint32 crc32(const quint8 *src, unsigned len, unsigned state) @@ -137,4 +140,17 @@ quint32 crc32(const quint8 *src, unsigned len, unsigned state)
return state;
}
bool fuzzyCompare(double value1, double value2)
{
if (qIsNaN(value1) && qIsNaN(value2)) {
return true;
} else if (qIsNaN(value1) || qIsNaN(value2)) {
return false;
} else if (value1 == value2) {
return true;
} else {
return qFuzzyCompare(value1, value2);
}
}
}

11
src/QGC.h

@ -7,9 +7,7 @@ @@ -7,9 +7,7 @@
*
****************************************************************************/
#ifndef QGC_H
#define QGC_H
#pragma once
#include <QDateTime>
#include <QColor>
@ -42,7 +40,8 @@ void initTimer(); @@ -42,7 +40,8 @@ void initTimer();
/** @brief Get the ground time since boot in milliseconds */
quint64 bootTimeMilliseconds();
const static int MAX_FLIGHT_TIME = 60 * 60 * 24 * 21;
/// Returns true if the two values are equal or close. Correctly handles 0 and NaN values.
bool fuzzyCompare(double value1, double value2);
class SLEEP : public QThread
{
@ -56,7 +55,3 @@ public: @@ -56,7 +55,3 @@ public:
quint32 crc32(const quint8 *src, unsigned len, unsigned state);
}
#define QGC_EVENTLOOP_DEBUG 0
#endif // QGC_H

Loading…
Cancel
Save