Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qfloat16 Class Reference

\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16 More...

#include <qfloat16.h>

+ Collaboration diagram for qfloat16:

Public Types

using NativeType = QtPrivate::NativeFloat16Type
 
using NearestFloat = std::conditional_t<IsNative, NativeType, float>
 

Public Member Functions

constexpr qfloat16 () noexcept
 
 qfloat16 (Qt::Initialization) noexcept
 
 qfloat16 (float f) noexcept
 
 operator float () const noexcept
 
template<typename T , typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, NearestFloat>>>
constexpr qfloat16 (T value) noexcept
 
bool isInf () const noexcept
 
bool isNaN () const noexcept
 
bool isFinite () const noexcept
 
Q_CORE_EXPORT int fpClassify () const noexcept
 
qfloat16 copySign (qfloat16 sign) const noexcept
 
constexpr bool isNormal () const noexcept
 

Static Public Member Functions

static constexpr qfloat16 _limit_epsilon () noexcept
 
static constexpr qfloat16 _limit_min () noexcept
 
static constexpr qfloat16 _limit_denorm_min () noexcept
 
static constexpr qfloat16 _limit_max () noexcept
 
static constexpr qfloat16 _limit_lowest () noexcept
 
static constexpr qfloat16 _limit_infinity () noexcept
 
static constexpr qfloat16 _limit_quiet_NaN () noexcept
 

Static Public Attributes

static constexpr bool IsNative = QFLOAT16_IS_NATIVE
 

Friends

bool qIsNull (qfloat16 f) noexcept
 
qfloat16 operator- (qfloat16 a) noexcept
 
qfloat16 operator+ (qfloat16 a, qfloat16 b) noexcept
 
qfloat16 operator- (qfloat16 a, qfloat16 b) noexcept
 
qfloat16 operator* (qfloat16 a, qfloat16 b) noexcept
 
qfloat16 operator/ (qfloat16 a, qfloat16 b) noexcept
 
size_t qHash (qfloat16 key, size_t seed=0) noexcept
 
QF16_CONSTEXPR bool comparesEqual (const qfloat16 &lhs, const qfloat16 &rhs) noexcept
 
QF16_CONSTEXPR Qt::partial_ordering compareThreeWay (const qfloat16 &lhs, const qfloat16 &rhs) noexcept
 
template<typename T , if_type_is_integral< T > = true>
QF16_CONSTEXPR bool comparesEqual (const qfloat16 &lhs, T rhs) noexcept
 
template<typename T , if_type_is_integral< T > = true>
QF16_CONSTEXPR Qt::partial_ordering compareThreeWay (const qfloat16 &lhs, T rhs) noexcept
 
QT_WARNING_POP friend Q_CORE_EXPORT QDataStreamoperator<< (QDataStream &ds, qfloat16 f)
 
Q_CORE_EXPORT QDataStreamoperator>> (QDataStream &ds, qfloat16 &f)
 
Q_CORE_EXPORT QTextStreamoperator<< (QTextStream &ts, qfloat16 f)
 
Q_CORE_EXPORT QTextStreamoperator>> (QTextStream &ts, qfloat16 &f)
 

Related Symbols

(Note that these are not member symbols.)

bool qIsInfqIsInf (qfloat16 f)(float)
 Returns true if the qfloat16 {f} is equivalent to infinity.
 
bool qIsNaNqIsNaN (qfloat16 f)(float)
 Returns true if the qfloat16 {f} is not a number (NaN).
 
bool qIsFiniteqIsFinite (qfloat16 f)(float)
 Returns true if the qfloat16 {f} is a finite number.
 
int qFpClassifyqFpClassify (qfloat16 val)(float)
 
int qRoundqRound (qfloat16 value)(float)
 Rounds value to the nearest integer.
 
qint64 qRound64qRound64 (qfloat16 value)(float)
 Rounds value to the nearest 64-bit integer.
 
bool qFuzzyCompareqFuzzyCompare (qfloat16 p1, qfloat16 p2)(float, float)
 Compares the floating point value p1 and p2 and returns true if they are considered equal, otherwise false.
 
Q_CORE_EXPORT void qFloatToFloat16 (qfloat16 *out, const float *in, qsizetype len) noexcept
 
Q_CORE_EXPORT void qFloatFromFloat16 (float *out, const qfloat16 *in, qsizetype len) noexcept
 

Detailed Description

\keyword 16-bit Floating Point Support

\inmodule QtCore \inheaderfile QFloat16

Provides 16-bit floating point support.

\compares partial \compareswith partial float double {long double} qint8 quint8 qint16 quint16 \ qint32 quint32 long {unsigned long} qint64 quint64 \endcompareswith \compareswith partial qint128 quint128 Comparison with 128-bit integral types is only supported if Qt provides these types. \endcompareswith

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.
Since
5.9

Definition at line 46 of file qfloat16.h.

Member Typedef Documentation

◆ NativeType

using qfloat16::NativeType = QtPrivate::NativeFloat16Type

Definition at line 70 of file qfloat16.h.

◆ NearestFloat

using qfloat16::NearestFloat = std::conditional_t<IsNative, NativeType, float>

Definition at line 73 of file qfloat16.h.

Constructor & Destructor Documentation

◆ qfloat16() [1/4]

constexpr qfloat16::qfloat16 ( )
inlineconstexprnoexcept

Definition at line 75 of file qfloat16.h.

Referenced by _limit_denorm_min(), _limit_epsilon(), _limit_infinity(), _limit_lowest(), _limit_max(), _limit_min(), _limit_quiet_NaN(), and copySign().

+ Here is the caller graph for this function:

◆ qfloat16() [2/4]

qfloat16::qfloat16 ( Qt::Initialization )
inlineexplicitnoexcept
Since
6.1

Constructs a qfloat16 without initializing the value.

Definition at line 76 of file qfloat16.h.

◆ qfloat16() [3/4]

QT_WARNING_PUSH qfloat16::qfloat16 ( float f)
inlinenoexcept

Definition at line 366 of file qfloat16.h.

References base, qMax(), and shift().

+ Here is the call graph for this function:

◆ qfloat16() [4/4]

template<typename T , typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, NearestFloat>>>
constexpr qfloat16::qfloat16 ( T value)
inlineexplicitconstexprnoexcept

Definition at line 86 of file qfloat16.h.

Member Function Documentation

◆ _limit_denorm_min()

static constexpr qfloat16 qfloat16::_limit_denorm_min ( )
inlinestaticconstexprnoexcept

Definition at line 115 of file qfloat16.h.

References qfloat16().

+ Here is the call graph for this function:

◆ _limit_epsilon()

static constexpr qfloat16 qfloat16::_limit_epsilon ( )
inlinestaticconstexprnoexcept

Definition at line 113 of file qfloat16.h.

References qfloat16().

+ Here is the call graph for this function:

◆ _limit_infinity()

static constexpr qfloat16 qfloat16::_limit_infinity ( )
inlinestaticconstexprnoexcept

Definition at line 118 of file qfloat16.h.

References qfloat16().

+ Here is the call graph for this function:

◆ _limit_lowest()

static constexpr qfloat16 qfloat16::_limit_lowest ( )
inlinestaticconstexprnoexcept

Definition at line 117 of file qfloat16.h.

References qfloat16().

+ Here is the call graph for this function:

◆ _limit_max()

static constexpr qfloat16 qfloat16::_limit_max ( )
inlinestaticconstexprnoexcept

Definition at line 116 of file qfloat16.h.

References qfloat16().

+ Here is the call graph for this function:

◆ _limit_min()

static constexpr qfloat16 qfloat16::_limit_min ( )
inlinestaticconstexprnoexcept

Definition at line 114 of file qfloat16.h.

References qfloat16().

+ Here is the call graph for this function:

◆ _limit_quiet_NaN()

static constexpr qfloat16 qfloat16::_limit_quiet_NaN ( )
inlinestaticconstexprnoexcept

Definition at line 119 of file qfloat16.h.

References qfloat16().

+ Here is the call graph for this function:

◆ copySign()

qfloat16 qfloat16::copySign ( qfloat16 sign) const
inlinenoexcept
Since
5.15

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

Definition at line 94 of file qfloat16.h.

References qfloat16(), b16, and sign().

+ Here is the call graph for this function:

◆ fpClassify()

int qfloat16::fpClassify ( ) const
noexcept
Since
5.14 Implements qFpClassify() for qfloat16.

Definition at line 141 of file qfloat16.cpp.

◆ isFinite()

bool qfloat16::isFinite ( ) const
inlinenoexcept
Since
5.14

Tests whether this qfloat16 value is finite.

Definition at line 91 of file qfloat16.h.

References b16.

◆ isInf()

bool qfloat16::isInf ( ) const
inlinenoexcept
Since
5.14

Tests whether this qfloat16 value is an infinity.

Definition at line 89 of file qfloat16.h.

References b16.

◆ isNaN()

bool qfloat16::isNaN ( ) const
inlinenoexcept
Since
5.14

Tests whether this qfloat16 value is "not a number".

Definition at line 90 of file qfloat16.h.

References b16.

◆ isNormal()

bool qfloat16::isNormal ( ) const
inlineconstexprnoexcept
Since
5.14

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

See also
qFpClassify()

Definition at line 124 of file qfloat16.h.

References b16.

◆ operator float()

QT_WARNING_POP qfloat16::operator float ( ) const
inlinenoexcept

Definition at line 404 of file qfloat16.h.

Friends And Related Symbol Documentation

◆ comparesEqual [1/2]

QF16_CONSTEXPR bool comparesEqual ( const qfloat16 & lhs,
const qfloat16 & rhs )
friend

Definition at line 219 of file qfloat16.h.

◆ comparesEqual [2/2]

template<typename T , if_type_is_integral< T > = true>
QF16_CONSTEXPR bool comparesEqual ( const qfloat16 & lhs,
T rhs )
friend

Definition at line 243 of file qfloat16.h.

◆ compareThreeWay [1/2]

QF16_CONSTEXPR Qt::partial_ordering compareThreeWay ( const qfloat16 & lhs,
const qfloat16 & rhs )
friend

Definition at line 222 of file qfloat16.h.

◆ compareThreeWay [2/2]

template<typename T , if_type_is_integral< T > = true>
QF16_CONSTEXPR Qt::partial_ordering compareThreeWay ( const qfloat16 & lhs,
T rhs )
friend

Definition at line 246 of file qfloat16.h.

◆ operator*

qfloat16 operator* ( qfloat16 a,
qfloat16 b )
friend

Definition at line 165 of file qfloat16.h.

◆ operator+

qfloat16 operator+ ( qfloat16 a,
qfloat16 b )
friend

Definition at line 163 of file qfloat16.h.

◆ operator- [1/2]

qfloat16 operator- ( qfloat16 a)
friend

Definition at line 156 of file qfloat16.h.

◆ operator- [2/2]

qfloat16 operator- ( qfloat16 a,
qfloat16 b )
friend

Definition at line 164 of file qfloat16.h.

◆ operator/

qfloat16 operator/ ( qfloat16 a,
qfloat16 b )
friend

Definition at line 166 of file qfloat16.h.

◆ operator<< [1/2]

QT_WARNING_POP friend Q_CORE_EXPORT QDataStream & operator<< ( QDataStream & ds,
qfloat16 f )
friend

Definition at line 400 of file qfloat16.cpp.

◆ operator<< [2/2]

Q_CORE_EXPORT QTextStream & operator<< ( QTextStream & ts,
qfloat16 f )
friend

Definition at line 431 of file qfloat16.cpp.

◆ operator>> [1/2]

Q_CORE_EXPORT QDataStream & operator>> ( QDataStream & ds,
qfloat16 & f )
friend

Definition at line 417 of file qfloat16.cpp.

◆ operator>> [2/2]

Q_CORE_EXPORT QTextStream & operator>> ( QTextStream & ts,
qfloat16 & f )
friend

Definition at line 423 of file qfloat16.cpp.

◆ qFloatFromFloat16()

Q_CORE_EXPORT void qFloatFromFloat16 ( float * out,
const qfloat16 * in,
qsizetype len )
related
Since
5.11

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.

Definition at line 366 of file qfloat16.cpp.

References hasFastF16(), i, out, and qFloatFromFloat16_fast().

+ Here is the call graph for this function:

◆ qFloatToFloat16()

Q_CORE_EXPORT void qFloatToFloat16 ( qfloat16 * out,
const float * in,
qsizetype len )
related
Since
5.11

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.

Definition at line 347 of file qfloat16.cpp.

References hasFastF16(), i, out, and qFloatToFloat16_fast().

+ Here is the call graph for this function:

◆ qFpClassifyqFpClassify()

int qFpClassifyqFpClassify ( qfloat16 val)
related
Since
5.14

Returns the floating-point class of val.

◆ qFuzzyCompareqFuzzyCompare()

bool qFuzzyCompareqFuzzyCompare ( qfloat16 p1,
qfloat16 p2 )
related

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.

◆ qHash

size_t qfloat16::qHash ( qfloat16 key,
size_t seed = 0 )
friend
Since
6.5.3

Returns the hash value for the key, using seed to seed the calculation.

Note
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.

Definition at line 168 of file qfloat16.h.

◆ qIsFiniteqIsFinite()

bool qIsFiniteqIsFinite ( qfloat16 f)
related

Returns true if the qfloat16 {f} is a finite number.

◆ qIsInfqIsInf()

bool qIsInfqIsInf ( qfloat16 f)
related

Returns true if the qfloat16 {f} is equivalent to infinity.

◆ qIsNaNqIsNaN()

bool qIsNaNqIsNaN ( qfloat16 f)
related

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

◆ qIsNull

bool qIsNull ( qfloat16 f)
friend

Definition at line 354 of file qfloat16.h.

◆ qRound64qRound64()

qint64 qRound64qRound64 ( qfloat16 value)
related

Rounds value to the nearest 64-bit integer.

◆ qRoundqRound()

int qRoundqRound ( qfloat16 value)
related

Rounds value to the nearest integer.

Member Data Documentation

◆ b16

quint16 qfloat16::b16

Definition at line 134 of file qfloat16.h.

Referenced by copySign(), isFinite(), isInf(), isNaN(), and isNormal().

◆ IsNative

constexpr bool qfloat16::IsNative = QFLOAT16_IS_NATIVE
staticconstexpr

Definition at line 72 of file qfloat16.h.


The documentation for this class was generated from the following files: