OpenVDB  12.0.0
Public Types | Public Member Functions | List of all members
half Class Reference

#include <openvdb/math/Half.h>

Public Types

using uif = imath_half_uif
 

Public Member Functions

 operator float () const noexcept
 Conversion to float. More...
 
constexpr half round (unsigned int n) const noexcept
 
Constructors
 half () noexcept=default
 
 half (float f) noexcept
 Construct from float. More...
 
constexpr half (FromBitsTag, uint16_t bits) noexcept
 Construct from bit-vector. More...
 
constexpr half (const half &) noexcept=default
 Copy constructor. More...
 
constexpr half (half &&) noexcept=default
 Move constructor. More...
 
 ~half () noexcept=default
 Destructor. More...
 
Basic Algebra
constexpr half operator- () const noexcept
 Unary minus. More...
 
halfoperator= (const half &h) noexcept=default
 Assignment. More...
 
halfoperator= (half &&h) noexcept=default
 Move assignment. More...
 
halfoperator= (float f) noexcept
 Assignment from float. More...
 
halfoperator+= (half h) noexcept
 Addition assignment. More...
 
halfoperator+= (float f) noexcept
 Addition assignment from float. More...
 
halfoperator-= (half h) noexcept
 Subtraction assignment. More...
 
halfoperator-= (float f) noexcept
 Subtraction assignment from float. More...
 
halfoperator*= (half h) noexcept
 Multiplication assignment. More...
 
halfoperator*= (float f) noexcept
 Multiplication assignment from float. More...
 
halfoperator/= (half h) noexcept
 Division assignment. More...
 
halfoperator/= (float f) noexcept
 Division assignment from float. More...
 
Classification
constexpr bool isFinite () const noexcept
 
constexpr bool isNormalized () const noexcept
 Return true if a normalized number. More...
 
constexpr bool isDenormalized () const noexcept
 Return true if a denormalized number. More...
 
constexpr bool isZero () const noexcept
 Return true if zero. More...
 
constexpr bool isNan () const noexcept
 Return true if NAN. More...
 
constexpr bool isInfinity () const noexcept
 Return true if a positive or a negative infinity. More...
 
constexpr bool isNegative () const noexcept
 Return true if the sign bit is set (negative) More...
 
Access to the internal representation
constexpr uint16_t bits () const noexcept
 Return the bit pattern. More...
 
constexpr void setBits (uint16_t bits) noexcept
 Set the bit pattern. More...
 

Static Public Member Functions

Special values
static constexpr half posInf () noexcept
 Return +infinity. More...
 
static constexpr half negInf () noexcept
 Return -infinity. More...
 
static constexpr half qNan () noexcept
 Returns a NAN with the bit pattern 0111111111111111. More...
 
static constexpr half sNan () noexcept
 Return a NAN with the bit pattern 0111110111111111. More...
 

Detailed Description

class half – 16-bit floating point number

Type half can represent positive and negative numbers whose magnitude is between roughly 6.1e-5 and 6.5e+4 with a relative error of 9.8e-4; numbers smaller than 6.1e-5 can be represented with an absolute error of 6.0e-8. All integers from -2048 to +2048 can be represented exactly.

Type half behaves (almost) like the built-in C++ floating point types. In arithmetic expressions, half, float and double can be mixed freely. Here are a few examples:

half a (3.5);
float b (a + sqrt (a));
a += b;
b += a;
b = a + 7;

Conversions from half to float are lossless; all half numbers are exactly representable as floats.

Conversions from float to half may not preserve a float's value exactly. If a float is not representable as a half, then the float value is rounded to the nearest representable half. If a float value is exactly in the middle between the two closest representable half values, then the float value is rounded to the closest half whose least significant bit is zero.

Overflows during float-to-half conversions cause arithmetic exceptions. An overflow occurs when the float value to be converted is too large to be represented as a half, or if the float value is an infinity or a NAN.

The implementation of type half makes the following assumptions about the implementation of the built-in C++ types:

Member Typedef Documentation

Constructor & Destructor Documentation

half ( )
defaultnoexcept

Default construction provides no initialization (hence it is not constexpr).

half ( float  f)
inlinenoexcept

Construct from float.

constexpr half ( FromBitsTag  ,
uint16_t  bits 
)
inlinenoexcept

Construct from bit-vector.

constexpr half ( const half )
defaultnoexcept

Copy constructor.

constexpr half ( half &&  )
defaultnoexcept

Move constructor.

~half ( )
defaultnoexcept

Destructor.

Member Function Documentation

constexpr uint16_t bits ( ) const
inlinenoexcept

Return the bit pattern.

constexpr bool isDenormalized ( ) const
inlinenoexcept

Return true if a denormalized number.

constexpr bool isFinite ( ) const
inlinenoexcept

Return true if a normalized number, a denormalized number, or zero.

constexpr bool isInfinity ( ) const
inlinenoexcept

Return true if a positive or a negative infinity.

constexpr bool isNan ( ) const
inlinenoexcept

Return true if NAN.

constexpr bool isNegative ( ) const
inlinenoexcept

Return true if the sign bit is set (negative)

constexpr bool isNormalized ( ) const
inlinenoexcept

Return true if a normalized number.

constexpr bool isZero ( ) const
inlinenoexcept

Return true if zero.

constexpr half negInf ( )
inlinestaticnoexcept

Return -infinity.

operator float ( ) const
inlinenoexcept

Conversion to float.

half & operator*= ( half  h)
inlinenoexcept

Multiplication assignment.

half & operator*= ( float  f)
inlinenoexcept

Multiplication assignment from float.

half & operator+= ( half  h)
inlinenoexcept

Addition assignment.

half & operator+= ( float  f)
inlinenoexcept

Addition assignment from float.

constexpr half operator- ( ) const
inlinenoexcept

Unary minus.

half & operator-= ( half  h)
inlinenoexcept

Subtraction assignment.

half & operator-= ( float  f)
inlinenoexcept

Subtraction assignment from float.

half & operator/= ( half  h)
inlinenoexcept

Division assignment.

half & operator/= ( float  f)
inlinenoexcept

Division assignment from float.

half& operator= ( const half h)
defaultnoexcept

Assignment.

half& operator= ( half &&  h)
defaultnoexcept

Move assignment.

half & operator= ( float  f)
inlinenoexcept

Assignment from float.

constexpr half posInf ( )
inlinestaticnoexcept

Return +infinity.

constexpr half qNan ( )
inlinestaticnoexcept

Returns a NAN with the bit pattern 0111111111111111.

constexpr half round ( unsigned int  n) const
inlinenoexcept

Round to n-bit precision (n should be between 0 and 10). After rounding, the significand's 10-n least significant bits will be zero.

constexpr void setBits ( uint16_t  bits)
inlinenoexcept

Set the bit pattern.

constexpr half sNan ( )
inlinestaticnoexcept

Return a NAN with the bit pattern 0111110111111111.