From b2a3389cfef08833b4a04c6bca35320d3e57b6f8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 11 Jan 2021 12:36:59 +0100 Subject: 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 --- src/corelib/global/qnumeric.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 +constexpr typename std::enable_if::value, bool>::type +qIsInf(T) { return false; } +template +constexpr typename std::enable_if::value, bool>::type +qIsNaN(T) { return false; } +template +constexpr typename std::enable_if::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 -- cgit v1.2.3