This reference page is linked to from the following overview topics: Math and Geometry Utilities.
Half precision (16 bit) float class.
Supports fast conversion between float and half precision.
Format is compatible with openEXRs half precision type. 1 sign bit, 5 exponent bits (bias = 15), 10 fraction bits.
#include <image.h>
Public Member Functions |
|
half_ () | |
half_ (float f) | |
operator float () const | |
half_ & | operator= (float f) |
half_ | ( | float | f | ) | [inline] |
Definition at line 41 of file image.h.
{ unsigned int x = *(unsigned int *)&f; unsigned int frac = (x >> 13) & 0x03ff; int exp = (int)((x >> 23) & 0xff) - 127; m_bits = (x >> 16) & 0x8000; // extract the sign bit if (exp > 16) { // handle overflows/underflows exp = 16; frac = 0x03ff; } else if (exp <= -15) { frac = 0; exp = -15; } m_bits |= ((exp + 15) << 10) | frac; }
operator float | ( | ) | const [inline] |
Definition at line 63 of file image.h.
{ int exp = (m_bits >> 10) & 0x1f; unsigned int f = (m_bits & 0x8000) << 16; // extract the sign bit unsigned int frac = (m_bits & 0x03ff) << 13; if (exp == 0x1f) { // convert 16-bit FP inf/NaN to 32-bit inf/NaN value exp = 0xff - ExponentBiasDelta; } else if (exp == 0) { exp = -ExponentBiasDelta; // convert 16-bit FP zero/denorm to 32-bit zero/denorm value } f |= ((exp + ExponentBiasDelta) << 23) | frac; return *(float *)&f; }
half_& operator= | ( | float | f | ) | [inline] |