From 0abc2addba98eade0a399b8619cd1032e3dbee2e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 23 Mar 2016 14:54:34 -0300 Subject: [PATCH] Change calls to isnan / isinf to qIsNan / qIsInf This way we don't need macro-magic to deal with different operating systems and compilers. Signed-off-by: Tomaz Canabrava --- src/QGC.h | 34 ---------------------------------- src/Vehicle/Vehicle.cc | 6 +++--- src/comm/QGCFlightGearLink.cc | 4 ++-- src/comm/QGCJSBSimLink.cc | 4 ++-- src/uas/UAS.cc | 8 ++++---- src/ui/QGCDataPlot2D.cc | 4 ++-- 6 files changed, 13 insertions(+), 47 deletions(-) diff --git a/src/QGC.h b/src/QGC.h index e6660abb6..19675520b 100644 --- a/src/QGC.h +++ b/src/QGC.h @@ -30,40 +30,6 @@ #include "QGCConfig.h" - -/* Windows fixes */ -#ifdef _MSC_VER -#if (_MSC_VER < 1800) /* only PRIOR to Visual Studio 2013 */ -/* Needed define for Eigen */ -//#define NOMINMAX -#include -template -inline bool isnan(T value) -{ - return value != value; - -} - -// requires #include -template -inline bool isinf(T value) -{ - return (value == std::numeric_limits::infinity() || (-1 * value) == std::numeric_limits::infinity()) && std::numeric_limits::has_infinity; -} -#endif -#elif defined __APPLE__ || defined Q_OS_LINUX -#include -#ifndef isnan -#define isnan(x) std::isnan(x) -#endif -#ifndef isinf -#define isinf(x) std::isinf(x) -#endif -#endif -#ifdef __android__ -#define isinf(x) std::isinf(x) -#endif - namespace QGC { const static int defaultSystemId = 255; diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 840e6fdf6..ab953efb3 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -783,17 +783,17 @@ void Vehicle::setLongitude(double longitude){ void Vehicle::_updateAttitude(UASInterface*, double roll, double pitch, double yaw, quint64) { - if (isinf(roll)) { + if (qIsInf(roll)) { _rollFact.setRawValue(0); } else { _rollFact.setRawValue(roll * (180.0 / M_PI)); } - if (isinf(pitch)) { + if (qIsInf(pitch)) { _pitchFact.setRawValue(0); } else { _pitchFact.setRawValue(pitch * (180.0 / M_PI)); } - if (isinf(yaw)) { + if (qIsInf(yaw)) { _headingFact.setRawValue(0); } else { yaw = yaw * (180.0 / M_PI); diff --git a/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index 2a520fbe8..16d2ed283 100644 --- a/src/comm/QGCFlightGearLink.cc +++ b/src/comm/QGCFlightGearLink.cc @@ -230,7 +230,7 @@ void QGCFlightGearLink::updateControls(quint64 time, float rollAilerons, float p Q_UNUSED(systemMode); Q_UNUSED(navMode); - if(!isnan(rollAilerons) && !isnan(pitchElevator) && !isnan(yawRudder) && !isnan(throttle)) + if(!qIsNaN(rollAilerons) && !qIsNaN(pitchElevator) && !qIsNaN(yawRudder) && !qIsNaN(throttle)) { QString state("%1\t%2\t%3\t%4\t%5\n"); state = state.arg(rollAilerons).arg(pitchElevator).arg(yawRudder).arg(true).arg(throttle); @@ -240,7 +240,7 @@ void QGCFlightGearLink::updateControls(quint64 time, float rollAilerons, float p } else { - qDebug() << "HIL: Got NaN values from the hardware: isnan output: roll: " << isnan(rollAilerons) << ", pitch: " << isnan(pitchElevator) << ", yaw: " << isnan(yawRudder) << ", throttle: " << isnan(throttle); + qDebug() << "HIL: Got NaN values from the hardware: isnan output: roll: " << qIsNaN(rollAilerons) << ", pitch: " << qIsNaN(pitchElevator) << ", yaw: " << qIsNaN(yawRudder) << ", throttle: " << qIsNaN(throttle); } } diff --git a/src/comm/QGCJSBSimLink.cc b/src/comm/QGCJSBSimLink.cc index 1210621bc..487240c92 100644 --- a/src/comm/QGCJSBSimLink.cc +++ b/src/comm/QGCJSBSimLink.cc @@ -242,7 +242,7 @@ void QGCJSBSimLink::updateControls(quint64 time, float rollAilerons, float pitch Q_UNUSED(systemMode); Q_UNUSED(navMode); - if(!isnan(rollAilerons) && !isnan(pitchElevator) && !isnan(yawRudder) && !isnan(throttle)) + if(!qIsNaN(rollAilerons) && !qIsNaN(pitchElevator) && !qIsNaN(yawRudder) && !qIsNaN(throttle)) { QString state("%1\t%2\t%3\t%4\t%5\n"); state = state.arg(rollAilerons).arg(pitchElevator).arg(yawRudder).arg(true).arg(throttle); @@ -250,7 +250,7 @@ void QGCJSBSimLink::updateControls(quint64 time, float rollAilerons, float pitch } else { - qDebug() << "HIL: Got NaN values from the hardware: isnan output: roll: " << isnan(rollAilerons) << ", pitch: " << isnan(pitchElevator) << ", yaw: " << isnan(yawRudder) << ", throttle: " << isnan(throttle); + qDebug() << "HIL: Got NaN values from the hardware: isnan output: roll: " << qIsNaN(rollAilerons) << ", pitch: " << qIsNaN(pitchElevator) << ", yaw: " << qIsNaN(yawRudder) << ", throttle: " << qIsNaN(throttle); } //qDebug() << "Updated controls" << state; } diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 6aba1c4b5..07d7b829f 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -441,7 +441,7 @@ void UAS::receiveMessage(mavlink_message_t message) setAltitudeAMSL(hud.alt); setGroundSpeed(hud.groundspeed); - if (!isnan(hud.airspeed)) + if (!qIsNaN(hud.airspeed)) setAirSpeed(hud.airspeed); speedZ = -hud.climb; emit altitudeChanged(this, altitudeAMSL, altitudeRelative, -speedZ, time); @@ -537,7 +537,7 @@ void UAS::receiveMessage(mavlink_message_t message) float vel = pos.vel/100.0f; // Smaller than threshold and not NaN - if ((vel < 1000000) && !isnan(vel) && !isinf(vel)) { + if ((vel < 1000000) && !qIsNaN(vel) && !qIsInf(vel)) { setGroundSpeed(vel); emit speedChanged(this, groundSpeed, airSpeed, time); } else { @@ -1309,8 +1309,8 @@ void UAS::setExternalControlSetpoint(float roll, float pitch, float yaw, float t if (countSinceLastTransmission++ >= 5) { sendCommand = true; countSinceLastTransmission = 0; - } else if ((!isnan(roll) && roll != manualRollAngle) || (!isnan(pitch) && pitch != manualPitchAngle) || - (!isnan(yaw) && yaw != manualYawAngle) || (!isnan(thrust) && thrust != manualThrust) || + } else if ((!qIsNaN(roll) && roll != manualRollAngle) || (!qIsNaN(pitch) && pitch != manualPitchAngle) || + (!qIsNaN(yaw) && yaw != manualYawAngle) || (!qIsNaN(thrust) && thrust != manualThrust) || buttons != manualButtons) { sendCommand = true; diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index 2e530b21e..bcfaecf8a 100644 --- a/src/ui/QGCDataPlot2D.cc +++ b/src/ui/QGCDataPlot2D.cc @@ -535,7 +535,7 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil { bool okx = true; x = text.toDouble(&okx); - if (okx && !isnan(x) && !isinf(x)) + if (okx && !qIsNaN(x) && !qIsInf(x)) { headerfound = true; } @@ -561,7 +561,7 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil y = text.toDouble(&oky); // Only INF is really an issue for the plot // NaN is fine - if (oky && !isnan(y) && !isinf(y) && text.length() > 0 && text != " " && text != "\n" && text != "\r" && text != "\t") + if (oky && !qIsNaN(y) && !qIsInf(y) && text.length() > 0 && text != " " && text != "\n" && text != "\r" && text != "\t") { // Only append definitely valid values xValues.value(curveName)->append(x); -- 2.22.0