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

## Static Public Member Functions

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

## 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:

- float is an IEEE 754 single-precision number
- sizeof (float) == 4
- sizeof (unsigned int) == sizeof (float)
- alignof (unsigned int) == alignof (float)
- sizeof (uint16_t) == 2

## Member Typedef Documentation

## uif

using uif = imath_half_uif

## Constructor & Destructor Documentation

## half() [1/5]

half | ( |  | ) |

defaultnoexcept

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

## half() [2/5]

half | ( | float | f | ) |

inlinenoexcept

Construct from float.

## half() [3/5]

half | ( | FromBitsTag | ,
|  | uint16_t | bits )

inlineconstexprnoexcept

Construct from bit-vector.

## half() [4/5]

half | ( | const half & |  | ) |

constexprdefaultnoexcept

Copy constructor.

## half() [5/5]

half | ( | half && |  | ) |

constexprdefaultnoexcept

Move constructor.

## ~half()

~half | ( |  | ) |

defaultnoexcept

Destructor.

## Member Function Documentation

## bits()

uint16_t bits | ( |  | ) | const

inlineconstexprnoexcept

Return the bit pattern.

## isDenormalized()

bool isDenormalized | ( |  | ) | const

inlineconstexprnoexcept

Return true if a denormalized number.

## isFinite()

bool isFinite | ( |  | ) | const

inlineconstexprnoexcept

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

## isInfinity()

bool isInfinity | ( |  | ) | const

inlineconstexprnoexcept

Return true if a positive or a negative infinity.

## isNan()

bool isNan | ( |  | ) | const

inlineconstexprnoexcept

Return true if NAN.

## isNegative()

bool isNegative | ( |  | ) | const

inlineconstexprnoexcept

Return true if the sign bit is set (negative)

## isNormalized()

bool isNormalized | ( |  | ) | const

inlineconstexprnoexcept

Return true if a normalized number.

## isZero()

bool isZero | ( |  | ) | const

inlineconstexprnoexcept

Return true if zero.

## negInf()

half negInf | ( |  | ) |

inlinestaticconstexprnoexcept

Return -infinity.

## operator float()

operator float | ( |  | ) | const

inlinenoexcept

Conversion to float.

## operator*=() [1/2]

half & operator*= | ( | float | f | ) |

inlinenoexcept

Multiplication assignment from float.

## operator*=() [2/2]

half & operator*= | ( | half | h | ) |

inlinenoexcept

Multiplication assignment.

## operator+=() [1/2]

half & operator+= | ( | float | f | ) |

inlinenoexcept

Addition assignment from float.

## operator+=() [2/2]

half & operator+= | ( | half | h | ) |

inlinenoexcept

Addition assignment.

## operator-()

half operator- | ( |  | ) | const

inlineconstexprnoexcept

Unary minus.

## operator-=() [1/2]

half & operator-= | ( | float | f | ) |

inlinenoexcept

Subtraction assignment from float.

## operator-=() [2/2]

half & operator-= | ( | half | h | ) |

inlinenoexcept

Subtraction assignment.

## operator/=() [1/2]

half & operator/= | ( | float | f | ) |

inlinenoexcept

Division assignment from float.

## operator/=() [2/2]

half & operator/= | ( | half | h | ) |

inlinenoexcept

Division assignment.

## operator=() [1/3]

half & operator= | ( | const half & | h | ) |

defaultnoexcept

Assignment.

## operator=() [2/3]

half & operator= | ( | float | f | ) |

inlinenoexcept

Assignment from float.

## operator=() [3/3]

half & operator= | ( | half && | h | ) |

defaultnoexcept

Move assignment.

## posInf()

half posInf | ( |  | ) |

inlinestaticconstexprnoexcept

Return +infinity.

## qNan()

half qNan | ( |  | ) |

inlinestaticconstexprnoexcept

Returns a NAN with the bit pattern 0111111111111111.

## round()

half round | ( | unsigned int | n | ) | const

inlineconstexprnoexcept

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.

## setBits()

void setBits | ( | uint16_t | bits | ) |

inlineconstexprnoexcept

Set the bit pattern.

## sNan()

half sNan | ( |  | ) |

inlinestaticconstexprnoexcept

Return a NAN with the bit pattern 0111110111111111.