summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qfloat16.h
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-02-27 11:17:45 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-03-26 13:06:50 +0000
commit921fa344e19218b650e44f3307943fe4ec77f098 (patch)
treef32dd9d8c8ddfd3654300ad092638e23b373f046 /src/corelib/global/qfloat16.h
parent920622b803629a454ef73284a0065fe31c3dc62c (diff)
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 <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qfloat16.h')
-rw-r--r--src/corelib/global/qfloat16.h14
1 files changed, 10 insertions, 4 deletions
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