class
#include <Magnum/Math/Half.h>
Half Half-precision float literal.
Represents a floating-point value in the binary16
format.
The sole purpose of this type is to make creation, conversion and visualization of half-float values easier. By design it doesn't support any arithmetic operations as not all CPU architecture have native support for half-floats and thus the operations would be done faster in a regular single-precision Float.
The class provides explicit conversion from and to Float, equality comparison with correct treatment of NaN values, promotion and negation operator, a Literals::
using namespace Math::Literals; Half a = 3.14159_h; Debug{} << a; // Prints 3.141 Debug{} << Float(a); // Prints 3.14062 Debug{} << UnsignedShort(a); // Prints 25675
Note that it is also possible to use this type inside Vector classes, though, again, only for passing data around and converting them, without any arithmetic operations:
Vector3h a{3.14159_h, -1.4142_h, 1.618_h}; Vector3 b{a}; // converts to 32-bit floats Debug{} << a; // prints {3.141, -1.414, 1.618} Debug{} << Vector3us{a}; // prints {16968, 48552, 15993}
Constructors, destructors, conversion operators
- Half() constexpr noexcept
- Default constructor.
- Half(ZeroInitT) explicit constexpr noexcept
- Construct a zero value.
- Half(UnsignedShort data) explicit constexpr noexcept
- Construct a half value from underlying 16-bit representation.
- Half(Float value) explicit noexcept
- Construct a half value from a 32-bit float representation.
- Half(Double value) explicit noexcept
- Construct a half value from a 64-bit float representation.
-
Half(Magnum::
NoInitT) explicit noexcept - Construct without initializing the contents.
- operator UnsignedShort() const explicit constexpr
- Conversion to underlying representation.
- operator Float() const explicit
- Conversion to 32-bit float representation.
Public functions
- auto operator==(Half other) const -> bool constexpr
- Equality comparison.
- auto operator!=(Half other) const -> bool constexpr
- Non-equality comparison.
- auto operator+() const -> Half constexpr
- Promotion.
- auto operator-() const -> Half constexpr
- Negation.
- auto data() const -> UnsignedShort constexpr
- Underlying representation.
Function documentation
Magnum:: Math:: Half:: operator UnsignedShort() const explicit constexpr
Conversion to underlying representation.
Magnum:: Math:: Half:: operator Float() const explicit
Conversion to 32-bit float representation.
bool Magnum:: Math:: Half:: operator==(Half other) const constexpr
Equality comparison.
Returns false
if one of the values is half-float representation of NaN, otherwise does bitwise comparison.
bool Magnum:: Math:: Half:: operator!=(Half other) const constexpr
Non-equality comparison.
Simply negates the result of operator==().
UnsignedShort Magnum:: Math:: Half:: data() const constexpr
Underlying representation.
Debug& operator<<(Debug& debug, Half value)
Debug output operator.
Prints the value with 4 significant digits.