Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_half.h File Reference

IEEE 754-2008 binary16 (half-precision) floating-point helpers. More...

#include <string.h>
#include <vl/vl_numtypes.h>
+ Include dependency graph for vl_half.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VL_HALF_SIGN_MASK   0x8000
 Sign bit mask.
 
#define VL_HALF_EXP_MASK   0x7C00
 Exponent field mask.
 
#define VL_HALF_FRAC_MASK   0x03FF
 Fraction (mantissa) mask.
 
#define VL_HALF_EXP_SHIFT   10
 Exponent field shift.
 
#define VL_HALF_EXP_BIAS   15
 Exponent bias for binary16.
 
#define VL_HALF_POS_ZERO   ((vl_half)0x0000)
 
#define VL_HALF_NEG_ZERO   ((vl_half)0x8000)
 
#define VL_HALF_POS_INF   ((vl_half)0x7C00)
 
#define VL_HALF_NEG_INF   ((vl_half)0xFC00)
 
#define VL_HALF_QNAN   ((vl_half)0x7E00) /* canonical quiet NaN */
 
#define VL_HALF_SNAN   ((vl_half)0x7D00) /* signaling NaN (payload = 0) */
 
#define VL_HALF_ONE   ((vl_half)0x3C00) /* 1.0 */
 
#define VL_HALF_NEG_ONE   ((vl_half)0xBC00) /* -1.0 */
 
#define VL_HALF_MAX   ((vl_half)0x7BFF) /* +65504 */
 
#define VL_HALF_MIN   ((vl_half)0xFBFF) /* -65504 */
 
#define VL_HALF_MIN_POS   ((vl_half)0x0400) /* 2^-14 */
 
#define VL_HALF_MIN_NEG   ((vl_half)0x8400)
 
#define VL_HALF_TRUE_MIN_POS   ((vl_half)0x0001) /* 2^-24 */
 
#define VL_HALF_TRUE_MIN_NEG   ((vl_half)0x8001)
 
#define VL_HALF_EPSILON   ((vl_half)0x1400) /* 2^-10 */
 

Typedefs

typedef vl_uint16_t vl_half_t
 Raw half-precision floating-point bit pattern.
 

Detailed Description

IEEE 754-2008 binary16 (half-precision) floating-point helpers.

██ ██ ██ █████ ███████ █████ ██████ ███ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ███ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ███████ ██ ██ ███████ ██ ██ ██████ ██ ████ ██ ██ ====—: A Data Structure and Algorithms library for C11. :—====

Copyright 2026 Jesse Walker, released under the MIT license. Git Repository: https://github.com/walkerje/veritable_lasagna

This header defines a portable, bit-exact representation of half-precision floating-point values (binary16) and a small set of inline helper functions for inspecting, classifying, packing, and converting them.

Design goals:

  • No reliance on compiler-specific half types (e.g. _Float16, __fp16)
  • No bitfields (avoids layout and endianness ambiguities)
  • No type-punning or strict-aliasing violations
  • Explicit, predictable semantics
  • Suitable for use in low-level systems code

The vl_half type represents the raw 16-bit IEEE-754 bit pattern. It is NOT a native C floating-point type.

Macro Definition Documentation

◆ VL_HALF_EPSILON

#define VL_HALF_EPSILON   ((vl_half)0x1400) /* 2^-10 */

◆ VL_HALF_EXP_BIAS

#define VL_HALF_EXP_BIAS   15

Exponent bias for binary16.

◆ VL_HALF_EXP_MASK

#define VL_HALF_EXP_MASK   0x7C00

Exponent field mask.

◆ VL_HALF_EXP_SHIFT

#define VL_HALF_EXP_SHIFT   10

Exponent field shift.

◆ VL_HALF_FRAC_MASK

#define VL_HALF_FRAC_MASK   0x03FF

Fraction (mantissa) mask.

◆ VL_HALF_MAX

#define VL_HALF_MAX   ((vl_half)0x7BFF) /* +65504 */

◆ VL_HALF_MIN

#define VL_HALF_MIN   ((vl_half)0xFBFF) /* -65504 */

◆ VL_HALF_MIN_NEG

#define VL_HALF_MIN_NEG   ((vl_half)0x8400)

◆ VL_HALF_MIN_POS

#define VL_HALF_MIN_POS   ((vl_half)0x0400) /* 2^-14 */

◆ VL_HALF_NEG_INF

#define VL_HALF_NEG_INF   ((vl_half)0xFC00)

◆ VL_HALF_NEG_ONE

#define VL_HALF_NEG_ONE   ((vl_half)0xBC00) /* -1.0 */

◆ VL_HALF_NEG_ZERO

#define VL_HALF_NEG_ZERO   ((vl_half)0x8000)

◆ VL_HALF_ONE

#define VL_HALF_ONE   ((vl_half)0x3C00) /* 1.0 */

◆ VL_HALF_POS_INF

#define VL_HALF_POS_INF   ((vl_half)0x7C00)

◆ VL_HALF_POS_ZERO

#define VL_HALF_POS_ZERO   ((vl_half)0x0000)

◆ VL_HALF_QNAN

#define VL_HALF_QNAN   ((vl_half)0x7E00) /* canonical quiet NaN */

◆ VL_HALF_SIGN_MASK

#define VL_HALF_SIGN_MASK   0x8000

Sign bit mask.

◆ VL_HALF_SNAN

#define VL_HALF_SNAN   ((vl_half)0x7D00) /* signaling NaN (payload = 0) */

◆ VL_HALF_TRUE_MIN_NEG

#define VL_HALF_TRUE_MIN_NEG   ((vl_half)0x8001)

◆ VL_HALF_TRUE_MIN_POS

#define VL_HALF_TRUE_MIN_POS   ((vl_half)0x0001) /* 2^-24 */

Typedef Documentation

◆ vl_half_t

typedef vl_uint16_t vl_half_t

Raw half-precision floating-point bit pattern.

This is a 16-bit unsigned integer holding an IEEE 754-2008 binary16 value:

sign : 1 bit exp : 5 bits (bias = 15) frac : 10 bits