From d6e0e34220682a6c3453030e5a1c3cc45c22b959 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Thu, 30 Jul 2020 13:03:06 -0700 Subject: [PATCH] Add QGC::fuzzyCompare which works in all cases --- src/QGC.cc | 16 ++++++++++++++++ src/QGC.h | 11 +++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/QGC.cc b/src/QGC.cc index 4d68bafdc..77e5a7baa 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 658835bd5..1debeed33 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 -- 2.22.0