summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-01-11 12:36:59 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-01-15 16:00:40 +0100
commitb2a3389cfef08833b4a04c6bca35320d3e57b6f8 (patch)
tree1228e445fcdf64b3d751f229b5b6ac415cb0c4ac
parent2f8428d3327d172f595bed6854964add349bbaee (diff)
Extend qIsInf() and friends to handle integral types sensibly
[ChangeLog][QtCore] qIsInf(), qIsNaN() and qIsFinite() now, like std::isinf() and friends, accept integral types (returning false, false and true, respectively) as well as floating-point ones. Change-Id: I1e2b7f033f0e8166c0b21e31a62b3e6d37b9344a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/corelib/global/qnumeric.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h
index 28285248c2..63ba2bb378 100644
--- a/src/corelib/global/qnumeric.h
+++ b/src/corelib/global/qnumeric.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -73,6 +73,18 @@
QT_BEGIN_NAMESPACE
+// To match std::is{inf,nan,finite} functions:
+template <typename T>
+constexpr typename std::enable_if<std::is_integral<T>::value, bool>::type
+qIsInf(T) { return false; }
+template <typename T>
+constexpr typename std::enable_if<std::is_integral<T>::value, bool>::type
+qIsNaN(T) { return false; }
+template <typename T>
+constexpr typename std::enable_if<std::is_integral<T>::value, bool>::type
+qIsFinite(T) { return true; }
+
+// Floating-point types (see qfloat16.h for its overloads).
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf(double d);
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN(double d);
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite(double d);
@@ -81,6 +93,7 @@ Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf(float f);
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN(float f);
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite(float f);
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify(float val);
+
#if QT_CONFIG(signaling_nan)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qSNaN();
#endif