qfloat16 类

提供 16 位浮点支持。 更多...

头: #include <QFloat16>
qmake: QT += core
Since: Qt 5.9

该类在 Qt 5.9 引入。

公共函数

qfloat16 copySign (qfloat16 sign ) const
bool isNormal () const
void qFloatFromFloat16 (float * out , const qfloat16 * in , qsizetype len )
void qFloatToFloat16 (qfloat16 * out , const float * in , qsizetype len )
bool qFuzzyCompare (qfloat16 p1 , qfloat16 p2 )
bool qIsFinite (qfloat16 f )
bool qIsInf (qfloat16 f )
bool qIsNaN (qfloat16 f )
qint64 qRound64 (qfloat16 value )
int qRound (qfloat16 value )

QT_NO_FLOAT16_OPERATORS

详细描述

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.

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

成员函数文档编制

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().

该函数在 Qt 5.15 引入。

bool qfloat16:: isNormal () const

返回 true 若此 qfloat16 值是有限的且采用正常形式。

该函数在 Qt 5.14 引入。

另请参阅 qFpClassify ().

相关非成员

void qFloatFromFloat16 ( float * out , const qfloat16 * in , qsizetype len )

转换 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.

该函数在 Qt 5.11 引入。

void qFloatToFloat16 ( qfloat16 * out , const float * in , qsizetype len )

转换 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.

该函数在 Qt 5.11 引入。

bool qFuzzyCompare ( qfloat16 p1 , qfloat16 p2 )

比较浮点值 p1 and p2 并返回 true 若它们被认为相等,否则 false .

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

bool qIsFinite ( qfloat16 f )

返回 true 若 qfloat16 f 是有限数。

另请参阅 qIsFinite.

bool qIsInf ( qfloat16 f )

返回 true 若 qfloat16 f 相当于无穷大。

另请参阅 qIsInf.

bool qIsNaN ( qfloat16 f )

返回 true 若 qfloat16 f 是 NaN (非数字)。

另请参阅 qIsNaN.

qint64 qRound64 ( qfloat16 value )

圆整 value 到最近 64 位整数。

另请参阅 qRound64.

int qRound ( qfloat16 value )

圆整 value 到最近整数。

另请参阅 qRound.

宏文档编制

QT_NO_FLOAT16_OPERATORS

Defining this macro disables the arithmetic operators for qfloat16.

This is only necessary on Visual Studio 2017 (and earlier) when including <QFloat16> and <bitset> in the same translation unit, which would otherwise cause a compilation error due to a toolchain bug (see [QTBUG-72073]).

该函数在 Qt 5.12.4 引入。