MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SmallFloat.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux::Kakshya {
4
5/**
6 * @brief IEEE 754 binary16 to binary32. Exact for every pattern; a NaN keeps its payload.
7 */
8[[nodiscard]] MAYAFLUX_API float half_to_float(uint16_t bits) noexcept;
9
10/**
11 * @brief IEEE 754 binary32 to binary16, rounding to nearest with ties to even.
12 *
13 * Values past the largest half become infinity, values below the smallest
14 * subnormal become a signed zero, and a NaN stays a NaN.
15 */
16[[nodiscard]] MAYAFLUX_API uint16_t float_to_half(float value) noexcept;
17
18/**
19 * @brief Decode a binary floating point pattern with the given field widths.
20 *
21 * The pattern is sign, exponent and mantissa from the top, with an IEEE style
22 * bias and an all-ones exponent for infinity and NaN. Half is 5 and 10,
23 * bfloat16 is 8 and 7.
24 */
25[[nodiscard]] MAYAFLUX_API double decode_small_float(
26 uint32_t bits, int exponent_bits, int mantissa_bits) noexcept;
27
28/**
29 * @brief Encode a double as a binary floating point pattern with the given field widths.
30 *
31 * Rounds once, to nearest with ties to even, straight from the double, so a
32 * float widened to double is never rounded twice. Overflow becomes infinity
33 * and NaN becomes a quiet NaN.
34 */
35[[nodiscard]] MAYAFLUX_API uint32_t encode_small_float(
36 double value, int exponent_bits, int mantissa_bits) noexcept;
37
38}
uint32_t encode_small_float(double value, int exponent_bits, int mantissa_bits) noexcept
Encode a double as a binary floating point pattern with the given field widths.
float half_to_float(uint16_t bits) noexcept
IEEE 754 binary16 to binary32.
Definition SmallFloat.cpp:5
double decode_small_float(uint32_t bits, int exponent_bits, int mantissa_bits) noexcept
Decode a binary floating point pattern with the given field widths.
uint16_t float_to_half(float value) noexcept
IEEE 754 binary32 to binary16, rounding to nearest with ties to even.