summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorGlen Mabey <Glen.Mabey@swri.org>2013-06-22 19:43:46 -0500
committerGlen Mabey <Glen.Mabey@swri.org>2017-01-31 14:21:42 +0000
commit3ab7016632c825949f32b72d06ac324b6672b9f6 (patch)
treea385f0389c9b0f37e8c2e4f19980392d16c0b409 /src/corelib
parente5d303cb9fb3ade3fae6d3f14a5f4fe139af63c9 (diff)
New qfloat16 class
This constitutes a fairly complete submission of an entirely new floating point type which conforms to IEEE 754 as a 16-bit storage class. Conversion between qfloat16 and float is currently performed through a sequence of lookup tables. Global-level functions qRound(), qRound64(), qFuzzyCompare(), qFuzzyIsNull(), and qIsNull() each with a qfloat16 parameter have been included for completeness. [ChangeLog][QtCore] Added new qfloat16 class. Change-Id: Ia52eb27846965c14f8140c00faf5ba33c9443976 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/global.pri14
-rw-r--r--src/corelib/global/qfloat16.cpp117
-rw-r--r--src/corelib/global/qfloat16.h225
-rw-r--r--src/corelib/global/qfloat16_p.h95
-rw-r--r--src/corelib/io/qdatastream.cpp23
-rw-r--r--src/corelib/io/qdatastream.h9
6 files changed, 482 insertions, 1 deletions
diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri
index d23706e631..9ae1e3a4ae 100644
--- a/src/corelib/global/global.pri
+++ b/src/corelib/global/global.pri
@@ -11,6 +11,8 @@ HEADERS += \
global/qendian.h \
global/qnumeric_p.h \
global/qnumeric.h \
+ global/qfloat16_p.h \
+ global/qfloat16.h \
global/qglobalstatic.h \
global/qlibraryinfo.h \
global/qlogging.h \
@@ -29,6 +31,7 @@ SOURCES += \
global/qlibraryinfo.cpp \
global/qmalloc.cpp \
global/qnumeric.cpp \
+ global/qfloat16.cpp \
global/qoperatingsystemversion.cpp \
global/qlogging.cpp \
global/qhooks.cpp
@@ -76,3 +79,14 @@ gcc:ltcg {
} else {
SOURCES += $$VERSIONTAGGING_SOURCES
}
+
+QMAKE_QFLOAT16_TABLES_GENERATE = global/qfloat16.h
+
+qtPrepareTool(QMAKE_QFLOAT16_TABLES, qfloat16-tables)
+
+qfloat16_tables.commands = $$QMAKE_QFLOAT16_TABLES ${QMAKE_FILE_OUT}
+qfloat16_tables.output = global/qfloat16tables.cpp
+qfloat16_tables.depends = $$QMAKE_QFLOAT16_TABLES
+qfloat16_tables.input = QMAKE_QFLOAT16_TABLES_GENERATE
+qfloat16_tables.variable_out = SOURCES
+QMAKE_EXTRA_COMPILERS += qfloat16_tables
diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp
new file mode 100644
index 0000000000..5264b56104
--- /dev/null
+++ b/src/corelib/global/qfloat16.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 by Southwest Research Institute (R)
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qfloat16_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*! \headerfile <QFloat16>
+
+ This header file provides support for half-precision (16-bit) floating
+ point data with the class \c qfloat16. It is fully compliant with IEEE
+ 754 as a storage type. This implies that any arithmetic operation on a
+ \c qfloat16 instance results in the value first being converted to a
+ \c float. This conversion to and from \c float is performed by hardware
+ when possible, but on processors that do not natively support half-precision,
+ the conversion is performed through a sequence of lookup table operations.
+
+ \c qfloat16 should be treated as if it were a POD (plain old data) type.
+ Consequently, none of the supported operations need any elaboration beyond
+ stating that it supports all arithmetic operators incident to floating point
+ types.
+
+ \since 5.9
+*/
+
+Q_STATIC_ASSERT_X(sizeof(float) == sizeof(quint32),
+ "qfloat16 assumes that floats are 32 bits wide");
+Q_STATIC_ASSERT_X(std::numeric_limits<float>::is_iec559,
+ "Only works with IEEE 754 floating point");
+
+/*!
+ Returns true if the \c qfloat16 \a {f} is equivalent to infinity.
+ \relates <QFloat16>
+
+ \sa qIsInf
+*/
+Q_REQUIRED_RESULT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW { return qt_is_inf(f); }
+
+/*!
+ Returns true if the \c qfloat16 \a {f} is not a number (NaN).
+ \relates <QFloat16>
+
+ \sa qIsNaN
+*/
+Q_REQUIRED_RESULT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW { return qt_is_nan(f); }
+
+/*!
+ Returns true if the \c qfloat16 \a {f} is a finite number.
+ \relates <QFloat16>
+
+ \sa qIsFinite
+*/
+Q_REQUIRED_RESULT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW { return qt_is_finite(f); }
+
+/*! \fn int qRound(qfloat16 value)
+ \relates <QFloat16>
+
+ Rounds \a value to the nearest integer.
+
+ \sa qRound
+*/
+
+/*! \fn qint64 qRound64(qfloat16 value)
+ \relates <QFloat16>
+
+ Rounds \a value to the nearest 64-bit integer.
+
+ \sa qRound64
+*/
+
+/*! \fn bool qFuzzyCompare(qfloat16 p1, qfloat16 p2)
+ \relates <QFloat16>
+
+ Compares the floating point value \a p1 and \a p2 and
+ returns \c true if they are considered equal, otherwise \c false.
+
+ The two numbers are compared in a relative way, where the
+ exactness is stronger the smaller the numbers are.
+ */
+
+QT_END_NAMESPACE
diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h
new file mode 100644
index 0000000000..5059108fb8
--- /dev/null
+++ b/src/corelib/global/qfloat16.h
@@ -0,0 +1,225 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 by Southwest Research Institute (R)
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QFLOAT16_H
+#define QFLOAT16_H
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qmetatype.h>
+#include <string.h>
+
+QT_BEGIN_NAMESPACE
+
+#if 0
+#pragma qt_class(QFloat16)
+#endif
+
+class qfloat16
+{
+public:
+#ifndef Q_QDOC
+ Q_DECL_CONSTEXPR inline qfloat16() Q_DECL_NOTHROW : b16(0) { }
+ inline qfloat16(float f) Q_DECL_NOTHROW;
+ inline operator float() const Q_DECL_NOTHROW;
+ inline operator double() const Q_DECL_NOTHROW;
+ inline operator long double() const Q_DECL_NOTHROW;
+#endif
+
+private:
+ quint16 b16;
+
+ Q_CORE_EXPORT static const quint32 mantissatable[];
+ Q_CORE_EXPORT static const quint32 exponenttable[];
+ Q_CORE_EXPORT static const quint32 offsettable[];
+ Q_CORE_EXPORT static const quint32 basetable[];
+ Q_CORE_EXPORT static const quint32 shifttable[];
+
+ friend bool qIsNull(qfloat16 f) Q_DECL_NOTHROW;
+ friend qfloat16 operator-(qfloat16 a) Q_DECL_NOTHROW;
+};
+
+Q_DECLARE_TYPEINFO(qfloat16, Q_PRIMITIVE_TYPE);
+
+Q_CORE_EXPORT Q_REQUIRED_RESULT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h
+Q_CORE_EXPORT Q_REQUIRED_RESULT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h
+Q_CORE_EXPORT Q_REQUIRED_RESULT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW; // complements qnumeric.h
+
+// The remainder of these utility functions complement qglobal.h
+inline Q_REQUIRED_RESULT int qRound(qfloat16 d) Q_DECL_NOTHROW
+{ return qRound(static_cast<float>(d)); }
+
+inline Q_REQUIRED_RESULT qint64 qRound64(qfloat16 d) Q_DECL_NOTHROW
+{ return qRound64(static_cast<float>(d)); }
+
+inline Q_REQUIRED_RESULT bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) Q_DECL_NOTHROW
+{
+ float f1 = static_cast<float>(p1);
+ float f2 = static_cast<float>(p2);
+ // The significand precision for IEEE754 half precision is
+ // 11 bits (10 explicitly stored), or approximately 3 decimal
+ // digits. In selecting the fuzzy comparison factor of 102.5f
+ // (that is, (2^10+1)/10) below, we effectively select a
+ // window of about 1 (least significant) decimal digit about
+ // which the two operands can vary and still return true.
+ return (qAbs(f1 - f2) * 102.5f <= qMin(qAbs(f1), qAbs(f2)));
+}
+
+inline Q_REQUIRED_RESULT bool qIsNull(qfloat16 f) Q_DECL_NOTHROW
+{
+ return (f.b16 & static_cast<quint16>(0x7fff)) == 0;
+}
+
+inline int qIntCast(qfloat16 f) Q_DECL_NOTHROW
+{ return int(static_cast<float>(f)); }
+
+inline qfloat16::qfloat16(float f) Q_DECL_NOTHROW
+{
+ quint32 u;
+ memcpy(&u, &f, sizeof(quint32));
+ b16 = basetable[(u >> 23) & 0x1ff]
+ + ((u & 0x007fffff) >> shifttable[(u >> 23) & 0x1ff]);
+}
+
+inline qfloat16::operator float() const Q_DECL_NOTHROW
+{
+ quint32 u = mantissatable[offsettable[b16 >> 10] + (b16 & 0x3ff)]
+ + exponenttable[b16 >> 10];
+ float f;
+ memcpy(&f, &u, sizeof(quint32));
+ return f;
+}
+
+inline qfloat16::operator double() const Q_DECL_NOTHROW
+{
+ return static_cast<double>(float(*this));
+}
+
+inline qfloat16::operator long double() const Q_DECL_NOTHROW
+{
+ return static_cast<long double>(float(*this));
+}
+
+inline qfloat16 operator-(qfloat16 a) Q_DECL_NOTHROW
+{
+ qfloat16 f;
+ f.b16 = a.b16 ^ quint16(0x8000);
+ return f;
+}
+
+inline qfloat16 operator+(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) + static_cast<float>(b)); }
+inline qfloat16 operator-(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) - static_cast<float>(b)); }
+inline qfloat16 operator*(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) * static_cast<float>(b)); }
+inline qfloat16 operator/(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat16(static_cast<float>(a) / static_cast<float>(b)); }
+
+#define QF16_MAKE_ARITH_OP_FP(FP, OP) \
+ inline FP operator OP(qfloat16 lhs, FP rhs) Q_DECL_NOTHROW { return static_cast<FP>(lhs) OP rhs; } \
+ inline FP operator OP(FP lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<FP>(rhs); }
+#define QF16_MAKE_ARITH_OP_EQ_FP(FP, OP_EQ, OP) \
+ inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) Q_DECL_NOTHROW { lhs = qfloat16(static_cast<FP>(lhs) OP rhs); return lhs; }
+#define QF16_MAKE_ARITH_OP(FP) \
+ QF16_MAKE_ARITH_OP_FP(FP, +) \
+ QF16_MAKE_ARITH_OP_FP(FP, -) \
+ QF16_MAKE_ARITH_OP_FP(FP, *) \
+ QF16_MAKE_ARITH_OP_FP(FP, /) \
+ QF16_MAKE_ARITH_OP_EQ_FP(FP, +=, +) \
+ QF16_MAKE_ARITH_OP_EQ_FP(FP, -=, -) \
+ QF16_MAKE_ARITH_OP_EQ_FP(FP, *=, *) \
+ QF16_MAKE_ARITH_OP_EQ_FP(FP, /=, /)
+QF16_MAKE_ARITH_OP(long double)
+QF16_MAKE_ARITH_OP(double)
+QF16_MAKE_ARITH_OP(float)
+#undef QF16_MAKE_ARITH_OP
+#undef QF16_MAKE_ARITH_OP_FP
+
+#define QF16_MAKE_ARITH_OP_INT(OP) \
+ inline double operator OP(qfloat16 lhs, int rhs) Q_DECL_NOTHROW { return static_cast<double>(lhs) OP rhs; } \
+ inline double operator OP(int lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<double>(rhs); }
+QF16_MAKE_ARITH_OP_INT(+)
+QF16_MAKE_ARITH_OP_INT(-)
+QF16_MAKE_ARITH_OP_INT(*)
+QF16_MAKE_ARITH_OP_INT(/)
+#undef QF16_MAKE_ARITH_OP_INT
+
+inline bool operator>(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) > static_cast<float>(b); }
+inline bool operator<(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) < static_cast<float>(b); }
+inline bool operator>=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) >= static_cast<float>(b); }
+inline bool operator<=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) <= static_cast<float>(b); }
+inline bool operator==(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) == static_cast<float>(b); }
+inline bool operator!=(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return static_cast<float>(a) != static_cast<float>(b); }
+
+#define QF16_MAKE_BOOL_OP_FP(FP, OP) \
+ inline bool operator OP(qfloat16 lhs, FP rhs) Q_DECL_NOTHROW { return static_cast<FP>(lhs) OP rhs; } \
+ inline bool operator OP(FP lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast<FP>(rhs); }
+#define QF16_MAKE_BOOL_OP(FP) \
+ QF16_MAKE_BOOL_OP_FP(FP, <) \
+ QF16_MAKE_BOOL_OP_FP(FP, >) \
+ QF16_MAKE_BOOL_OP_FP(FP, >=) \
+ QF16_MAKE_BOOL_OP_FP(FP, <=) \
+ QF16_MAKE_BOOL_OP_FP(FP, ==) \
+ QF16_MAKE_BOOL_OP_FP(FP, !=)
+QF16_MAKE_BOOL_OP(long double)
+QF16_MAKE_BOOL_OP(double)
+QF16_MAKE_BOOL_OP(float)
+#undef QF16_MAKE_BOOL_OP
+#undef QF16_MAKE_BOOL_OP_FP
+
+#define QF16_MAKE_BOOL_OP_INT(OP) \
+ inline bool operator OP(qfloat16 a, int b) Q_DECL_NOTHROW { return static_cast<float>(a) OP b; } \
+ inline bool operator OP(int a, qfloat16 b) Q_DECL_NOTHROW { return a OP static_cast<float>(b); }
+QF16_MAKE_BOOL_OP_INT(>)
+QF16_MAKE_BOOL_OP_INT(<)
+QF16_MAKE_BOOL_OP_INT(>=)
+QF16_MAKE_BOOL_OP_INT(<=)
+QF16_MAKE_BOOL_OP_INT(==)
+QF16_MAKE_BOOL_OP_INT(!=)
+#undef QF16_MAKE_BOOL_OP_INT
+
+/*!
+ \internal
+*/
+inline Q_REQUIRED_RESULT bool qFuzzyIsNull(qfloat16 f) Q_DECL_NOTHROW
+{
+ return qAbs(static_cast<float>(f)) <= 0.001f;
+}
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(qfloat16)
+
+#endif // QFLOAT16_H
diff --git a/src/corelib/global/qfloat16_p.h b/src/corelib/global/qfloat16_p.h
new file mode 100644
index 0000000000..ae52e64435
--- /dev/null
+++ b/src/corelib/global/qfloat16_p.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 by Southwest Research Institute (R)
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QFLOAT16_P_H
+#define QFLOAT16_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qfloat16.h>
+#include <QtCore/qsysinfo.h>
+
+QT_BEGIN_NAMESPACE
+
+static inline bool qt_is_inf(qfloat16 d) Q_DECL_NOTHROW
+{
+ bool is_inf;
+ uchar *ch = (uchar *)&d;
+ if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ is_inf = (ch[0] & 0x7c) == 0x7c;
+ else
+ is_inf = (ch[1] & 0x7c) == 0x7c;
+ return is_inf;
+}
+
+static inline bool qt_is_nan(qfloat16 d) Q_DECL_NOTHROW
+{
+ bool is_nan;
+ uchar *ch = (uchar *)&d;
+ if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ is_nan = (ch[0] & 0x7c) == 0x7c && (ch[0] & 0x02) != 0;
+ else
+ is_nan = (ch[1] & 0x7c) == 0x7c && (ch[1] & 0x02) != 0;
+ return is_nan;
+}
+
+static inline bool qt_is_finite(qfloat16 d) Q_DECL_NOTHROW
+{
+ bool is_finite;
+ uchar *ch = (uchar *)&d;
+ if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
+ is_finite = (ch[0] & 0x7c) != 0x7c;
+ else
+ is_finite = (ch[1] & 0x7c) != 0x7c;
+ return is_finite;
+}
+
+
+QT_END_NAMESPACE
+
+#endif // QFLOAT16_P_H
diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp
index 2730fd7f11..cac5152e87 100644
--- a/src/corelib/io/qdatastream.cpp
+++ b/src/corelib/io/qdatastream.cpp
@@ -448,6 +448,9 @@ QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const
The default is DoublePrecision.
+ Note that this property does not affect the serialization or deserialization of \c qfloat16
+ instances.
+
\warning This property must be set to the same value on the object that writes and the object
that reads the data stream.
@@ -972,6 +975,16 @@ QDataStream &QDataStream::operator>>(double &f)
/*!
+ \fn QDataStream &QDataStream::operator>>(qfloat16 &f)
+ \overload
+ \since 5.9
+
+ Reads a floating point number from the stream into \a f,
+ using the standard IEEE 754 format. Returns a reference to the
+ stream.
+*/
+
+/*!
\overload
Reads the '\\0'-terminated string \a s from the stream and returns
@@ -1260,6 +1273,15 @@ QDataStream &QDataStream::operator<<(double f)
/*!
+ \fn QDataStream &QDataStream::operator<<(qfloat16 f)
+ \overload
+ \since 5.9
+
+ Writes a floating point number, \a f, to the stream using
+ the standard IEEE 754 format. Returns a reference to the stream.
+*/
+
+/*!
\overload
Writes the '\\0'-terminated string \a s to the stream and returns a
@@ -1282,7 +1304,6 @@ QDataStream &QDataStream::operator<<(const char *s)
return *this;
}
-
/*!
Writes the length specifier \a len and the buffer \a s to the
stream and returns a reference to the stream.
diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h
index 994ed88791..9a7d7e275d 100644
--- a/src/corelib/io/qdatastream.h
+++ b/src/corelib/io/qdatastream.h
@@ -43,6 +43,7 @@
#include <QtCore/qscopedpointer.h>
#include <QtCore/qiodevice.h>
#include <QtCore/qpair.h>
+#include <QtCore/qfloat16.h>
#ifdef Status
#error qdatastream.h must be included before any header file that defines Status
@@ -154,6 +155,7 @@ public:
QDataStream &operator>>(quint64 &i);
QDataStream &operator>>(bool &i);
+ QDataStream &operator>>(qfloat16 &f);
QDataStream &operator>>(float &f);
QDataStream &operator>>(double &f);
QDataStream &operator>>(char *&str);
@@ -167,6 +169,7 @@ public:
QDataStream &operator<<(qint64 i);
QDataStream &operator<<(quint64 i);
QDataStream &operator<<(bool i);
+ QDataStream &operator<<(qfloat16 f);
QDataStream &operator<<(float f);
QDataStream &operator<<(double f);
QDataStream &operator<<(const char *str);
@@ -345,6 +348,9 @@ inline QDataStream &QDataStream::operator>>(quint32 &i)
inline QDataStream &QDataStream::operator>>(quint64 &i)
{ return *this >> reinterpret_cast<qint64&>(i); }
+inline QDataStream &QDataStream::operator>>(qfloat16 &f)
+{ return *this >> reinterpret_cast<qint16&>(f); }
+
inline QDataStream &QDataStream::operator<<(quint8 i)
{ return *this << qint8(i); }
@@ -357,6 +363,9 @@ inline QDataStream &QDataStream::operator<<(quint32 i)
inline QDataStream &QDataStream::operator<<(quint64 i)
{ return *this << qint64(i); }
+inline QDataStream &QDataStream::operator<<(qfloat16 f)
+{ return *this << reinterpret_cast<qint16&>(f); }
+
template <typename T>
inline QDataStream &operator>>(QDataStream &s, QList<T> &l)
{