qfloat16 類

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

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

此類 partially comparable .

此類 partially comparable with float, double , long double, qint8 , quint8 , qint16 , quint16 , qint32 , quint32 , long, unsigned long, qint64 ,和 quint64 .

此類 partially comparable with qint128 and quint128 .

Comparison with 128-bit integral types is only supported if Qt provides these types.

公共函數

(從 6.1 起) qfloat16 (Qt::Initialization)
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 )
int qFpClassify (qfloat16 val )
bool qFuzzyCompare (qfloat16 p1 , qfloat16 p2 )
(since 6.5.3) size_t qHash (qfloat16 key , size_t seed = 0)
bool qIsFinite (qfloat16 f )
bool qIsInf (qfloat16 f )
bool qIsNaN (qfloat16 f )
qint64 qRound64 (qfloat16 value )
int qRound (qfloat16 value )
QDataStream & operator<< (QDataStream & ds , qfloat16 f )
QDataStream & operator>> (QDataStream & ds , qfloat16 & f )

詳細描述

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.

成員函數文檔編製

[explicit noexcept, since 6.1] qfloat16:: qfloat16 ( Qt::Initialization )

Constructs a qfloat16 without initializing the value.

該函數在 Qt 6.1 引入。

[noexcept] 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().

[constexpr noexcept] bool qfloat16:: isNormal () const

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

另請參閱 qFpClassify ().

相關非成員

[noexcept] 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.

[noexcept] 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.

[noexcept] int qFpClassify ( qfloat16 val )

此函數重載 qFpClassify (float).

Returns the floating-point class of val .

[noexcept] bool qFuzzyCompare ( qfloat16 p1 , qfloat16 p2 )

此函數重載 qFuzzyCompare (float, float).

比較浮點值 p1 and p2 並返迴 true 若它們被認為相等,否則 false .

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

[noexcept, since 6.5.3] size_t qHash ( qfloat16 key , size_t seed = 0)

返迴哈希值為 key ,使用 seed 做計算種子。

注意: In Qt versions before 6.5, this operation was provided by the qHash(float) overload. In Qt versions 6.5.0 to 6.5.2, this functionality was broken in various ways. In Qt versions 6.5.3 and 6.6 onwards, this overload restores the Qt 6.4 behavior.

This function was introduced in Qt 6.5.3.

[noexcept] bool qIsFinite ( qfloat16 f )

此函數重載 qIsFinite (float).

返迴 true 若 qfloat16 f 是有限數。

[noexcept] bool qIsInf ( qfloat16 f )

此函數重載 qIsInf (float).

返迴 true 若 qfloat16 f 相當於無窮大。

[noexcept] bool qIsNaN ( qfloat16 f )

此函數重載 qIsNaN (float).

返迴 true 若 qfloat16 f 是 NaN (非數字)。

[noexcept] qint64 qRound64 ( qfloat16 value )

此函數重載 qRound64 (float).

圓整 value 到最近 64 位整數。

[noexcept] int qRound ( qfloat16 value )

此函數重載 qRound (float).

圓整 value 到最近整數。

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.

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

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.

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