diff --git a/src/QGC.cc b/src/QGC.cc index 4d68bafdc9464356b0e46e80c4736fb04b4646e7..77e5a7baa0c12f68caaf9832d23c6eab328b434e 100644 --- a/src/QGC.cc +++ b/src/QGC.cc @@ -9,9 +9,12 @@ #include "QGC.h" + #include #include +#include + namespace QGC { @@ -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); + } +} + } diff --git a/src/QGC.h b/src/QGC.h index 658835bd533b6bcc7fe49d2ebf5cd4b217801511..1debeed33622ae42c16644c2dac5155f9f79e7cc 100644 --- a/src/QGC.h +++ b/src/QGC.h @@ -7,9 +7,7 @@ * ****************************************************************************/ - -#ifndef QGC_H -#define QGC_H +#pragma once #include #include @@ -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: quint32 crc32(const quint8 *src, unsigned len, unsigned state); } - -#define QGC_EVENTLOOP_DEBUG 0 - -#endif // QGC_H