Ptex

Public Member Functions | Static Public Member Functions | Public Attributes | Static Private Member Functions | Static Private Attributes | List of all members
PtexHalf Class Reference

Half-precision (16-bit) floating-point type. More...

`#include <PtexHalf.h>`

## Public Member Functions
| PtexHalf ()
| Default constructor, value is undefined. More...
| PtexHalf (float val)
| PtexHalf (double val)
| operator float () const
PtexHalf & | operator= (float val)

## Static Public Member Functions
static float | toFloat (uint16_t h)
static uint16_t | fromFloat (float val)

## Public Attributes
uint16_t | bits

## Static Private Member Functions
static uint16_t | fromFloat_except (uint32_t val)
| Handle exceptional cases for half-to-float conversion. More...

## Static Private Attributes
static uint32_t | h2fTable [65536]
static uint16_t | f2hTable [512]

## Detailed Description

Half-precision (16-bit) floating-point type.

This type should be compatible with opengl, openexr, and IEEE 754r. The range is [-65504.0, 65504.0] and the precision is about 1 part in 2000 (3.3 decimal places).

From OpenGL spec 2.1.2:

A 16-bit floating-point number has a 1-bit sign (S), a 5-bit exponent (E), and a 10-bit mantissa (M). The value of a 16-bit floating-point number is determined by the following:

         (-1)^S * 0.0,                        if E == 0 and M == 0,
         (-1)^S * 2^-14 * (M/2^10),           if E == 0 and M != 0,
         (-1)^S * 2^(E-15) * (1 + M/2^10),    if 0 < E < 31,
         (-1)^S * INF,                        if E == 31 and M == 0, or
         NaN,                                 if E == 31 and M != 0

Definition at line 88 of file PtexHalf.h.

## Constructor & Destructor Documentation

## ◆ PtexHalf() [1/3]

PtexHalf::PtexHalf | ( |  | ) |
| inline

Default constructor, value is undefined.

Definition at line 92 of file PtexHalf.h.

## ◆ PtexHalf() [2/3]

PtexHalf::PtexHalf | ( | float | val | ) |
| inline

Definition at line 93 of file PtexHalf.h.

## ◆ PtexHalf() [3/3]

PtexHalf::PtexHalf | ( | double | val | ) |
| inline

Definition at line 94 of file PtexHalf.h.

## Member Function Documentation

## ◆ fromFloat()

static uint16_t PtexHalf::fromFloat | ( | float | val | ) |
| inline static

Definition at line 105 of file PtexHalf.h.

References f2hTable, and fromFloat_except().

Referenced by operator=().

## ◆ fromFloat_except()

PTEX_NAMESPACE_BEGIN uint16_t PtexHalf::fromFloat_except | ( | uint32_t | val | ) |
| static private

Handle exceptional cases for half-to-float conversion.

Definition at line 44 of file PtexHalf.cpp.

Referenced by fromFloat().

## ◆ operator float()

PtexHalf::operator float | ( |  | ) | const
| inline

Definition at line 95 of file PtexHalf.h.

References bits, and toFloat().

## ◆ operator=()

PtexHalf& PtexHalf::operator= | ( | float | val | ) |
| inline

Definition at line 96 of file PtexHalf.h.

References bits, and fromFloat().

## ◆ toFloat()

static float PtexHalf::toFloat | ( | uint16_t | h | ) |
| inline static

Definition at line 98 of file PtexHalf.h.

References h2fTable.

Referenced by operator float().

## Member Data Documentation

## ◆ bits

uint16_t PtexHalf::bits

Definition at line 89 of file PtexHalf.h.

Referenced by operator float(), and operator=().

## ◆ f2hTable

PTEXAPI uint16_t PtexHalf::f2hTable
| static private

Definition at line 121 of file PtexHalf.h.

Referenced by fromFloat().

## ◆ h2fTable

PTEXAPI uint32_t PtexHalf::h2fTable
| static private

Definition at line 120 of file PtexHalf.h.

Referenced by toFloat().

The documentation for this class was generated from the following files:

- PtexHalf.h
- PtexHalf.cpp
- PtexHalfTables.h