www.digitalmars.com Sargon Component Library for D




sargon.halffloat

Implement IEEE 754 half-precision binary floating point format binary16.

This a 16 bit type, and consists of a sign bit, a 5 bit exponent, and a 10 bit significand. All operations on HalfFloat are CTFE'able.

References:
Wikipedia

License:
Boost License 1.0

Authors:
Walter Bright

Source:
src/sargon/halffloat.d

struct HalfFloat;
The half precision floating point type.

The only operations are:
  • explicit conversion of float to HalfFloat
  • implicit conversion of HalfFloat to float
It operates in an analogous manner to shorts, which are converted to ints before performing any operations, and explicitly cast back to shorts. The half float is considered essentially a storage type, not a computation type.

Example:
   HalfFloat h = hf!27.2f;
   HalfFloat j = cast(HalfFloat)( hf!3.5f + hf!5 );
   HalfFloat f = HalfFloat(0.0f);

BUGS:
The only rounding mode currently supported is Round To Nearest. The exceptions OVERFLOW, UNDERFLOW and INEXACT are not thrown.

static @property HalfFloat min_normal();
static @property HalfFloat max();
static @property HalfFloat nan();
static @property HalfFloat infinity();
static @property HalfFloat epsilon();
int dig;

int mant_dig;

int max_10_exp;

int max_exp;

int min_10_exp;

int min_exp;

template hf(float v)
User defined literal for Half Float.

Example:
auto h = hf!1.3f;