|
Veritable Lasagna
An Allocator & Data Structure Library for C.
|
IEEE 754-2008 binary16 (half-precision) floating-point helpers. More...
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. | |
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:
The vl_half type represents the raw 16-bit IEEE-754 bit pattern. It is NOT a native C floating-point type.
| #define VL_HALF_EPSILON ((vl_half)0x1400) /* 2^-10 */ |
| #define VL_HALF_EXP_BIAS 15 |
Exponent bias for binary16.
| #define VL_HALF_EXP_MASK 0x7C00 |
Exponent field mask.
| #define VL_HALF_EXP_SHIFT 10 |
Exponent field shift.
| #define VL_HALF_FRAC_MASK 0x03FF |
Fraction (mantissa) mask.
| #define VL_HALF_MAX ((vl_half)0x7BFF) /* +65504 */ |
| #define VL_HALF_MIN ((vl_half)0xFBFF) /* -65504 */ |
| #define VL_HALF_MIN_NEG ((vl_half)0x8400) |
| #define VL_HALF_MIN_POS ((vl_half)0x0400) /* 2^-14 */ |
| #define VL_HALF_NEG_INF ((vl_half)0xFC00) |
| #define VL_HALF_NEG_ONE ((vl_half)0xBC00) /* -1.0 */ |
| #define VL_HALF_NEG_ZERO ((vl_half)0x8000) |
| #define VL_HALF_ONE ((vl_half)0x3C00) /* 1.0 */ |
| #define VL_HALF_POS_INF ((vl_half)0x7C00) |
| #define VL_HALF_POS_ZERO ((vl_half)0x0000) |
| #define VL_HALF_QNAN ((vl_half)0x7E00) /* canonical quiet NaN */ |
| #define VL_HALF_SIGN_MASK 0x8000 |
Sign bit mask.
| #define VL_HALF_SNAN ((vl_half)0x7D00) /* signaling NaN (payload = 0) */ |
| #define VL_HALF_TRUE_MIN_NEG ((vl_half)0x8001) |
| #define VL_HALF_TRUE_MIN_POS ((vl_half)0x0001) /* 2^-24 */ |
| 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