qfloat16 Class

Provides 16-bit floating point support. More...

Header: #include <QFloat16>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Since: Qt 5.9

Public Functions

qfloat16(float f)
qfloat16(Qt::Initialization)
qfloat16()
qfloat16 copySign(qfloat16 sign) const
bool isNormal() const
float operator float() const

Static Public Members

qfloat16 _limit_denorm_min()
qfloat16 _limit_epsilon()
qfloat16 _limit_infinity()
qfloat16 _limit_lowest()
qfloat16 _limit_max()
qfloat16 _limit_min()
qfloat16 _limit_quiet_NaN()
qfloat16 _limit_signaling_NaN()
void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype len)
void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len)
int qFpClassify(qfloat16 val)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2)
bool qIsFinite(qfloat16 f)
bool qIsInf(qfloat16 f)
bool qIsNaN(qfloat16 f)
bool qIsNull(qfloat16 f)
qint64 qRound64(qfloat16 value)
int qRound(qfloat16 value)
bool operator!=(qfloat16 a, qfloat16 b)
bool operator!=(qfloat16 lhs, long double rhs)
bool operator!=(long double lhs, qfloat16 rhs)
bool operator!=(qfloat16 lhs, double rhs)
bool operator!=(double lhs, qfloat16 rhs)
bool operator!=(qfloat16 lhs, float rhs)
bool operator!=(float lhs, qfloat16 rhs)
bool operator!=(qfloat16 a, int b)
bool operator!=(int a, qfloat16 b)
qfloat16 operator*(qfloat16 a, qfloat16 b)
long double operator*(qfloat16 lhs, long double rhs)
long double operator*(long double lhs, qfloat16 rhs)
double operator*(qfloat16 lhs, double rhs)
double operator*(double lhs, qfloat16 rhs)
float operator*(qfloat16 lhs, float rhs)
float operator*(float lhs, qfloat16 rhs)
double operator*(qfloat16 lhs, int rhs)
double operator*(int lhs, qfloat16 rhs)
qfloat16 &operator*=(qfloat16 &lhs, long double rhs)
qfloat16 &operator*=(qfloat16 &lhs, double rhs)
qfloat16 &operator*=(qfloat16 &lhs, float rhs)
qfloat16 operator+(qfloat16 a, qfloat16 b)
long double operator+(qfloat16 lhs, long double rhs)
long double operator+(long double lhs, qfloat16 rhs)
double operator+(qfloat16 lhs, double rhs)
double operator+(double lhs, qfloat16 rhs)
float operator+(qfloat16 lhs, float rhs)
float operator+(float lhs, qfloat16 rhs)
double operator+(qfloat16 lhs, int rhs)
double operator+(int lhs, qfloat16 rhs)
qfloat16 &operator+=(qfloat16 &lhs, long double rhs)
qfloat16 &operator+=(qfloat16 &lhs, double rhs)
qfloat16 &operator+=(qfloat16 &lhs, float rhs)
qfloat16 operator-(qfloat16 a)
qfloat16 operator-(qfloat16 a, qfloat16 b)
long double operator-(qfloat16 lhs, long double rhs)
long double operator-(long double lhs, qfloat16 rhs)
double operator-(qfloat16 lhs, double rhs)
double operator-(double lhs, qfloat16 rhs)
float operator-(qfloat16 lhs, float rhs)
float operator-(float lhs, qfloat16 rhs)
double operator-(qfloat16 lhs, int rhs)
double operator-(int lhs, qfloat16 rhs)
qfloat16 &operator-=(qfloat16 &lhs, long double rhs)
qfloat16 &operator-=(qfloat16 &lhs, double rhs)
qfloat16 &operator-=(qfloat16 &lhs, float rhs)
qfloat16 operator/(qfloat16 a, qfloat16 b)
long double operator/(qfloat16 lhs, long double rhs)
long double operator/(long double lhs, qfloat16 rhs)
double operator/(qfloat16 lhs, double rhs)
double operator/(double lhs, qfloat16 rhs)
float operator/(qfloat16 lhs, float rhs)
float operator/(float lhs, qfloat16 rhs)
double operator/(qfloat16 lhs, int rhs)
double operator/(int lhs, qfloat16 rhs)
qfloat16 &operator/=(qfloat16 &lhs, long double rhs)
qfloat16 &operator/=(qfloat16 &lhs, double rhs)
qfloat16 &operator/=(qfloat16 &lhs, float rhs)
bool operator<(qfloat16 a, qfloat16 b)
bool operator<(qfloat16 lhs, long double rhs)
bool operator<(long double lhs, qfloat16 rhs)
bool operator<(qfloat16 lhs, double rhs)
bool operator<(double lhs, qfloat16 rhs)
bool operator<(qfloat16 lhs, float rhs)
bool operator<(float lhs, qfloat16 rhs)
bool operator<(qfloat16 a, int b)
bool operator<(int a, qfloat16 b)
QDataStream &operator<<(QDataStream &ds, qfloat16 f)
bool operator<=(qfloat16 a, qfloat16 b)
bool operator<=(qfloat16 lhs, long double rhs)
bool operator<=(long double lhs, qfloat16 rhs)
bool operator<=(qfloat16 lhs, double rhs)
bool operator<=(double lhs, qfloat16 rhs)
bool operator<=(qfloat16 lhs, float rhs)
bool operator<=(float lhs, qfloat16 rhs)
bool operator<=(qfloat16 a, int b)
bool operator<=(int a, qfloat16 b)
bool operator==(qfloat16 a, qfloat16 b)
bool operator==(qfloat16 lhs, long double rhs)
bool operator==(long double lhs, qfloat16 rhs)
bool operator==(qfloat16 lhs, double rhs)
bool operator==(double lhs, qfloat16 rhs)
bool operator==(qfloat16 lhs, float rhs)
bool operator==(float lhs, qfloat16 rhs)
bool operator==(qfloat16 a, int b)
bool operator==(int a, qfloat16 b)
bool operator>(qfloat16 a, qfloat16 b)
bool operator>(qfloat16 lhs, long double rhs)
bool operator>(long double lhs, qfloat16 rhs)
bool operator>(qfloat16 lhs, double rhs)
bool operator>(double lhs, qfloat16 rhs)
bool operator>(qfloat16 lhs, float rhs)
bool operator>(float lhs, qfloat16 rhs)
bool operator>(qfloat16 a, int b)
bool operator>(int a, qfloat16 b)
bool operator>=(qfloat16 a, qfloat16 b)
bool operator>=(qfloat16 lhs, long double rhs)
bool operator>=(long double lhs, qfloat16 rhs)
bool operator>=(qfloat16 lhs, double rhs)
bool operator>=(double lhs, qfloat16 rhs)
bool operator>=(qfloat16 lhs, float rhs)
bool operator>=(float lhs, qfloat16 rhs)
bool operator>=(qfloat16 a, int b)
bool operator>=(int a, qfloat16 b)
QDataStream &operator>>(QDataStream &ds, qfloat16 &f)

Detailed Description

The qfloat16 class provides support for half-precision (16-bit) floating point data. It is fully compliant with IEEE 754 as a storage type. This implies that any arithmetic operation on a qfloat16 instance results in the value first being converted to a float. This conversion to and from 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.

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.

Note: On x86 and x86-64 that to get hardware accelerated conversions you must compile with F16C or AVX2 enabled, or use qFloatToFloat16() and qFloatFromFloat16() which will detect F16C at runtime.

Member Function Documentation

qfloat16::qfloat16(float f)

Default constructs an instance of qfloat16.

[since 6.1] qfloat16::qfloat16(Qt::Initialization)

Constructs a qfloat16 without initializing the value.

This function was introduced in Qt 6.1.

qfloat16::qfloat16()

Default constructs an instance of qfloat16.

[static] qfloat16 qfloat16::_limit_denorm_min()

[static] qfloat16 qfloat16::_limit_epsilon()

[static] qfloat16 qfloat16::_limit_infinity()

[static] qfloat16 qfloat16::_limit_lowest()

[static] qfloat16 qfloat16::_limit_max()

[static] qfloat16 qfloat16::_limit_min()

[static] qfloat16 qfloat16::_limit_quiet_NaN()

[static] qfloat16 qfloat16::_limit_signaling_NaN()

[since 5.15] qfloat16 qfloat16::copySign(qfloat16 sign) const

Returns a qfloat16 with the sign of sign but the rest of its value taken from this qfloat16. Serves as qfloat16's equivalent of std::copysign().

This function was introduced in Qt 5.15.

[since 5.14] bool qfloat16::isNormal() const

Returns true if this qfloat16 value is finite and in normal form.

This function was introduced in Qt 5.14.

See also qFpClassify().

float qfloat16::operator float() const

Related Non-Members

[since 5.11] void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype len)

Converts len qfloat16 from in to floats and stores them in out. Both in and out must have len allocated entries.

This function is faster than converting values one by one, and will do runtime F16C detection on x86 and x86-64 hardware.

This function was introduced in Qt 5.11.

[since 5.11] void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len)

Converts len floats from in to qfloat16 and stores them in out. Both in and out must have len allocated entries.

This function is faster than converting values one by one, and will do runtime F16C detection on x86 and x86-64 hardware.

This function was introduced in Qt 5.11.

[since 5.14] int qFpClassify(qfloat16 val)

This function overloads qFpClassify(float).

Returns the floating-point class of val.

This function was introduced in Qt 5.14.

bool qFuzzyCompare(qfloat16 p1, qfloat16 p2)

This function overloads qFuzzyCompare(float, float).

Compares the floating point value p1 and p2 and returns true if they are considered equal, otherwise false.

The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are.

bool qIsFinite(qfloat16 f)

This function overloads qIsFinite(float).

Returns true if the qfloat16 f is a finite number.

bool qIsInf(qfloat16 f)

This function overloads qIsInf(float).

Returns true if the qfloat16 f is equivalent to infinity.

bool qIsNaN(qfloat16 f)

This function overloads qIsNaN(float).

Returns true if the qfloat16 f is not a number (NaN).

bool qIsNull(qfloat16 f)

qint64 qRound64(qfloat16 value)

This function overloads qRound64(float).

Rounds value to the nearest 64-bit integer.

int qRound(qfloat16 value)

This function overloads qRound(float).

Rounds value to the nearest integer.

bool operator!=(qfloat16 a, qfloat16 b)

bool operator!=(qfloat16 lhs, long double rhs)

bool operator!=(long double lhs, qfloat16 rhs)

bool operator!=(qfloat16 lhs, double rhs)

bool operator!=(double lhs, qfloat16 rhs)

bool operator!=(qfloat16 lhs, float rhs)

bool operator!=(float lhs, qfloat16 rhs)

bool operator!=(qfloat16 a, int b)

bool operator!=(int a, qfloat16 b)

qfloat16 operator*(qfloat16 a, qfloat16 b)

long double operator*(qfloat16 lhs, long double rhs)

long double operator*(long double lhs, qfloat16 rhs)

double operator*(qfloat16 lhs, double rhs)

double operator*(double lhs, qfloat16 rhs)

float operator*(qfloat16 lhs, float rhs)

float operator*(float lhs, qfloat16 rhs)

double operator*(qfloat16 lhs, int rhs)

double operator*(int lhs, qfloat16 rhs)

qfloat16 &operator*=(qfloat16 &lhs, long double rhs)

qfloat16 &operator*=(qfloat16 &lhs, double rhs)

qfloat16 &operator*=(qfloat16 &lhs, float rhs)

qfloat16 operator+(qfloat16 a, qfloat16 b)

long double operator+(qfloat16 lhs, long double rhs)

long double operator+(long double lhs, qfloat16 rhs)

double operator+(qfloat16 lhs, double rhs)

double operator+(double lhs, qfloat16 rhs)

float operator+(qfloat16 lhs, float rhs)

float operator+(float lhs, qfloat16 rhs)

double operator+(qfloat16 lhs, int rhs)

double operator+(int lhs, qfloat16 rhs)

qfloat16 &operator+=(qfloat16 &lhs, long double rhs)

qfloat16 &operator+=(qfloat16 &lhs, double rhs)

qfloat16 &operator+=(qfloat16 &lhs, float rhs)

qfloat16 operator-(qfloat16 a)

qfloat16 operator-(qfloat16 a, qfloat16 b)

long double operator-(qfloat16 lhs, long double rhs)

long double operator-(long double lhs, qfloat16 rhs)

double operator-(qfloat16 lhs, double rhs)

double operator-(double lhs, qfloat16 rhs)

float operator-(qfloat16 lhs, float rhs)

float operator-(float lhs, qfloat16 rhs)

double operator-(qfloat16 lhs, int rhs)

double operator-(int lhs, qfloat16 rhs)

qfloat16 &operator-=(qfloat16 &lhs, long double rhs)

qfloat16 &operator-=(qfloat16 &lhs, double rhs)

qfloat16 &operator-=(qfloat16 &lhs, float rhs)

qfloat16 operator/(qfloat16 a, qfloat16 b)

long double operator/(qfloat16 lhs, long double rhs)

long double operator/(long double lhs, qfloat16 rhs)

double operator/(qfloat16 lhs, double rhs)

double operator/(double lhs, qfloat16 rhs)

float operator/(qfloat16 lhs, float rhs)

float operator/(float lhs, qfloat16 rhs)

double operator/(qfloat16 lhs, int rhs)

double operator/(int lhs, qfloat16 rhs)

qfloat16 &operator/=(qfloat16 &lhs, long double rhs)

qfloat16 &operator/=(qfloat16 &lhs, double rhs)

qfloat16 &operator/=(qfloat16 &lhs, float rhs)

bool operator<(qfloat16 a, qfloat16 b)

bool operator<(qfloat16 lhs, long double rhs)

bool operator<(long double lhs, qfloat16 rhs)

bool operator<(qfloat16 lhs, double rhs)

bool operator<(double lhs, qfloat16 rhs)

bool operator<(qfloat16 lhs, float rhs)

bool operator<(float lhs, qfloat16 rhs)

bool operator<(qfloat16 a, int b)

bool operator<(int a, qfloat16 b)

[since 5.9] QDataStream &operator<<(QDataStream &ds, qfloat16 f)

Writes a floating point number, f, to the stream ds using the standard IEEE 754 format. Returns a reference to the stream.

Note: In Qt versions prior to 6.3, this was a member function on QDataStream.

This function was introduced in Qt 5.9.

bool operator<=(qfloat16 a, qfloat16 b)

bool operator<=(qfloat16 lhs, long double rhs)

bool operator<=(long double lhs, qfloat16 rhs)

bool operator<=(qfloat16 lhs, double rhs)

bool operator<=(double lhs, qfloat16 rhs)

bool operator<=(qfloat16 lhs, float rhs)

bool operator<=(float lhs, qfloat16 rhs)

bool operator<=(qfloat16 a, int b)

bool operator<=(int a, qfloat16 b)

bool operator==(qfloat16 a, qfloat16 b)

bool operator==(qfloat16 lhs, long double rhs)

bool operator==(long double lhs, qfloat16 rhs)

bool operator==(qfloat16 lhs, double rhs)

bool operator==(double lhs, qfloat16 rhs)

bool operator==(qfloat16 lhs, float rhs)

bool operator==(float lhs, qfloat16 rhs)

bool operator==(qfloat16 a, int b)

bool operator==(int a, qfloat16 b)

bool operator>(qfloat16 a, qfloat16 b)

bool operator>(qfloat16 lhs, long double rhs)

bool operator>(long double lhs, qfloat16 rhs)

bool operator>(qfloat16 lhs, double rhs)

bool operator>(double lhs, qfloat16 rhs)

bool operator>(qfloat16 lhs, float rhs)

bool operator>(float lhs, qfloat16 rhs)

bool operator>(qfloat16 a, int b)

bool operator>(int a, qfloat16 b)

bool operator>=(qfloat16 a, qfloat16 b)

bool operator>=(qfloat16 lhs, long double rhs)

bool operator>=(long double lhs, qfloat16 rhs)

bool operator>=(qfloat16 lhs, double rhs)

bool operator>=(double lhs, qfloat16 rhs)

bool operator>=(qfloat16 lhs, float rhs)

bool operator>=(float lhs, qfloat16 rhs)

bool operator>=(qfloat16 a, int b)

bool operator>=(int a, qfloat16 b)

[since 5.9] QDataStream &operator>>(QDataStream &ds, qfloat16 &f)

Reads a floating point number from the stream ds into f, using the standard IEEE 754 format. Returns a reference to the stream.

Note: In Qt versions prior to 6.3, this was a member function on QDataStream.

This function was introduced in Qt 5.9.

© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.