half
2.2
IEEE 754-based half-precision floating-point library
|
Half-precision floating-point type. More...
Public Member Functions | |
Construction and assignment | |
constexpr | half () noexcept |
Default constructor. More... | |
half (float rhs) | |
Conversion constructor. More... | |
operator float () const | |
Conversion to single-precision. More... | |
half & | operator= (float rhs) |
Assignment operator. More... | |
Arithmetic updates | |
half & | operator+= (half rhs) |
Arithmetic assignment. More... | |
half & | operator-= (half rhs) |
Arithmetic assignment. More... | |
half & | operator*= (half rhs) |
Arithmetic assignment. More... | |
half & | operator/= (half rhs) |
Arithmetic assignment. More... | |
half & | operator+= (float rhs) |
Arithmetic assignment. More... | |
half & | operator-= (float rhs) |
Arithmetic assignment. More... | |
half & | operator*= (float rhs) |
Arithmetic assignment. More... | |
half & | operator/= (float rhs) |
Arithmetic assignment. More... | |
Increment and decrement | |
half & | operator++ () |
Prefix increment. More... | |
half & | operator-- () |
Prefix decrement. More... | |
half | operator++ (int) |
Postfix increment. More... | |
half | operator-- (int) |
Postfix decrement. More... | |
Half-precision floating-point type.
This class implements an IEEE-conformant half-precision floating-point type with the usual arithmetic operators and conversions. It is implicitly convertible to single-precision floating-point, which makes artihmetic expressions and functions with mixed-type operands to be of the most precise operand type.
According to the C++98/03 definition, the half type is not a POD type. But according to C++11's less strict and extended definitions it is both a standard layout type and a trivially copyable type (even if not a POD type), which means it can be standard-conformantly copied using raw binary copies. But in this context some more words about the actual size of the type. Although the half is representing an IEEE 16-bit type, it does not neccessarily have to be of exactly 16-bits size. But on any reasonable implementation the actual binary representation of this type will most probably not ivolve any additional "magic" or padding beyond the simple binary representation of the underlying 16-bit IEEE number, even if not strictly guaranteed by the standard. But even then it only has an actual size of 16 bits if your C++ implementation supports an unsigned integer type of exactly 16 bits width. But this should be the case on nearly any reasonable platform.
So if your C++ implementation is not totally exotic or imposes special alignment requirements, it is a reasonable assumption that the data of a half is just comprised of the 2 bytes of the underlying IEEE representation.
|
inlineconstexprnoexcept |
Default constructor.
This initializes the half to 0. Although this does not match the builtin types' default-initialization semantics and may be less efficient than no initialization, it is needed to provide proper value-initialization semantics.
|
inlineexplicit |
Conversion constructor.
rhs | float to convert |
FE_OVERFLOW,...UNDERFLOW,...INEXACT | according to rounding |
|
inline |
Conversion to single-precision.
|
inline |
Assignment operator.
rhs | single-precision value to copy from |
FE_OVERFLOW,...UNDERFLOW,...INEXACT | according to rounding |
Arithmetic assignment.
T | type of concrete half expression |
rhs | half expression to add |
FE_... | according to operator+(half,half) |
Arithmetic assignment.
T | type of concrete half expression |
rhs | half expression to subtract |
FE_... | according to operator-(half,half) |
Arithmetic assignment.
T | type of concrete half expression |
rhs | half expression to multiply with |
FE_... | according to operator*(half,half) |
Arithmetic assignment.
T | type of concrete half expression |
rhs | half expression to divide by |
FE_... | according to operator/(half,half) |
|
inline |
Arithmetic assignment.
rhs | single-precision value to add |
FE_... | according to operator=() |
|
inline |
Arithmetic assignment.
rhs | single-precision value to subtract |
FE_... | according to operator=() |
|
inline |
Arithmetic assignment.
rhs | single-precision value to multiply with |
FE_... | according to operator=() |
|
inline |
Arithmetic assignment.
rhs | single-precision value to divide by |
FE_... | according to operator=() |
|
inline |
|
inline |
|
inline |
Postfix increment.
FE_... | according to operator+(half,half) |
|
inline |
Postfix decrement.
FE_... | according to operator-(half,half) |