From 921fa344e19218b650e44f3307943fe4ec77f098 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 27 Feb 2019 11:17:45 +0100 Subject: Simplify finite/NaN testing for qfloat16 Doing endian-dependent selection of bytes of the value was a clumsy surrogate for just accessing the intenal quint16 shifted suitably. Change-Id: Icfd9d1d18f69eb94b041b8d32275df606c14c2b4 Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- src/corelib/global/qfloat16.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/corelib/global/qfloat16.h') diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 42cb1357f1..e823d0298b 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -67,10 +67,14 @@ QT_BEGIN_NAMESPACE class qfloat16 { public: - Q_DECL_CONSTEXPR inline qfloat16() Q_DECL_NOTHROW : b16(0) { } + constexpr inline qfloat16() Q_DECL_NOTHROW : b16(0) {} inline qfloat16(float f) Q_DECL_NOTHROW; inline operator float() const Q_DECL_NOTHROW; + // Support for qIs{Inf,NaN,Finite}: + bool isInf() const Q_DECL_NOTHROW { return ((b16 >> 8) & 0x7e) == 0x7c; } + bool isNaN() const Q_DECL_NOTHROW { return ((b16 >> 8) & 0x7e) == 0x7e; } + bool isFinite() const Q_DECL_NOTHROW { return ((b16 >> 8) & 0x7c) != 0x7c; } private: quint16 b16; @@ -89,9 +93,11 @@ Q_DECLARE_TYPEINFO(qfloat16, Q_PRIMITIVE_TYPE); Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *, const float *, qsizetype length) Q_DECL_NOTHROW; Q_CORE_EXPORT void qFloatFromFloat16(float *, const qfloat16 *, qsizetype length) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h -Q_REQUIRED_RESULT Q_CORE_EXPORT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h -Q_REQUIRED_RESULT Q_CORE_EXPORT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h +// Complement qnumeric.h: +Q_REQUIRED_RESULT inline bool qIsInf(qfloat16 f) Q_DECL_NOTHROW { return f.isInf(); } +Q_REQUIRED_RESULT inline bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW { return f.isNaN(); } +Q_REQUIRED_RESULT inline bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW { return f.isFinite(); } +// Q_REQUIRED_RESULT quint32 qFloatDistance(qfloat16 a, qfloat16 b); // The remainder of these utility functions complement qglobal.h Q_REQUIRED_RESULT inline int qRound(qfloat16 d) Q_DECL_NOTHROW -- cgit v1.2.3