PtexHalf Class Reference

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

`#include <PtexHalf.h>`

## Public Member Functions

| PtexHalf ()
| Default constructor, value is undefined.
| 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.

## 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 72 of file PtexHalf.h.

## Constructor & Destructor Documentation

## PtexHalf() [1/3]

PtexHalf::PtexHalf | ( |  | ) |

inline

Default constructor, value is undefined.

Definition at line 76 of file PtexHalf.h.

## PtexHalf() [2/3]

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

inline

Definition at line 77 of file PtexHalf.h.

## PtexHalf() [3/3]

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

inline

Definition at line 78 of file PtexHalf.h.

## Member Function Documentation

## fromFloat()

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

inlinestatic

Definition at line 89 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 | ) |

staticprivate

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 79 of file PtexHalf.h.

References bits, and toFloat().

## operator=()

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

inline

Definition at line 80 of file PtexHalf.h.

References bits, and fromFloat().

## toFloat()

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

inlinestatic

Definition at line 82 of file PtexHalf.h.

References h2fTable.

Referenced by operator float().

## Member Data Documentation

## bits

uint16_t PtexHalf::bits

Definition at line 73 of file PtexHalf.h.

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

## f2hTable

PTEXAPI uint16_t PtexHalf::f2hTable

staticprivate

Definition at line 8195 of file PtexHalf.h.

Referenced by fromFloat().

## h2fTable

PTEXAPI uint32_t PtexHalf::h2fTable

staticprivate

Definition at line 1 of file PtexHalf.h.

Referenced by toFloat().

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

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