qfloat16 Class
The qfloat16 class provides 16-bit floating point support. More…
| Header | #include <qfloat16> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| qfloat16() | |
| qfloat16(float value) | |
| qfloat16(T value) | |
| operator float() const | |
| bool | isInf() const |
| bool | isNaN() const |
| bool | isFinite() const |
| bool | isNormal() const |
| int | fpClassify() const |
| qfloat16 | copySign(qfloat16 sign) const |
| qfloat16 & | operator+=(qfloat16 other) |
| qfloat16 & | operator-=(qfloat16 other) |
| qfloat16 & | operator*=(qfloat16 other) |
| qfloat16 & | operator/=(qfloat16 other) |
| qfloat16 | operator-() const |
Detailed Description
The type is an IEEE 754 binary16 number: 1 sign bit, 5 exponent bits and 10 mantissa bits, which gives about three decimal digits and a range of about 6e-8 to 65504. It is meant for storing values compactly, for example in textures and tensors; arithmetic is done by converting to float and rounding the result back.
qfloat16 h(1.5f);
float f = h * 2.0f; // 3.0f
Values that are too large become infinity, and values that are too small become zero or a subnormal number. Conversions round to nearest, with ties going to the even value.
Differences from Qt
The conversions are always done in software; there is no use of hardware half-precision instructions. qFloatToFloat16() and qFloatFromFloat16() convert arrays one element at a time.
Member Function Documentation
qfloat16::qfloat16()
Constructs a qfloat16 with the value zero.
qfloat16::qfloat16(float value)
Constructs a qfloat16 from value, rounded to the nearest half-precision number.
template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, float>>>qfloat16::qfloat16(T value)
This is an overloaded function.
Constructs a qfloat16 from the integer or double value, converted through float.
qfloat16 qfloat16::copySign(qfloat16 sign) const
Returns this value with the sign of sign.
int qfloat16::fpClassify() const
Returns the category of the value, one of FP_NAN, FP_INFINITE, FP_ZERO, FP_SUBNORMAL and FP_NORMAL.
bool qfloat16::isFinite() const
Returns true if the value is neither infinity nor not a number.
bool qfloat16::isInf() const
Returns true if the value is positive or negative infinity.
See also isNaN() and isFinite().
bool qfloat16::isNaN() const
Returns true if the value is not a number.
See also isInf() and isFinite().
bool qfloat16::isNormal() const
Returns true if the value is normal: not zero, subnormal, infinite or a NaN.
qfloat16::operator float() const
Returns the value as a float, which is exact.
qfloat16 & qfloat16::operator*=(qfloat16 other)
Multiplies this value by other and returns this object.
qfloat16 & qfloat16::operator+=(qfloat16 other)
Adds other to this value and returns this object.
qfloat16 qfloat16::operator-() const
Returns this value with its sign flipped.
qfloat16 & qfloat16::operator-=(qfloat16 other)
Subtracts other from this value and returns this object.
qfloat16 & qfloat16::operator/=(qfloat16 other)
Divides this value by other and returns this object.