MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ half_to_float()

MAYAFLUX_API float MayaFlux::Kakshya::half_to_float ( uint16_t bits)
nodiscardnoexcept

IEEE 754 binary16 to binary32.

Exact for every pattern; a NaN keeps its payload.

Definition at line 5 of file SmallFloat.cpp.

6{
7 const uint32_t sign = static_cast<uint32_t>(bits & 0x8000U) << 16;
8 const uint32_t exponent = (bits >> 10) & 0x1FU;
9 const uint32_t mantissa = bits & 0x3FFU;
10
11 uint32_t pattern {};
12 if (exponent == 0) {
13 if (mantissa == 0) {
14 pattern = sign;
15 } else {
16 uint32_t shifts = 0;
17 uint32_t normalised = mantissa;
18 while ((normalised & 0x400U) == 0) {
19 normalised <<= 1;
20 ++shifts;
21 }
22 normalised &= 0x3FFU;
23 pattern = sign | ((113U - shifts) << 23) | (normalised << 13);
24 }
25 } else if (exponent == 0x1FU) {
26 pattern = sign | 0x7F800000U | (mantissa << 13);
27 } else {
28 pattern = sign | ((exponent - 15U + 127U) << 23) | (mantissa << 13);
29 }
30
31 float value {};
32 std::memcpy(&value, &pattern, sizeof(value));
33 return value;
34}
std::shared_ptr< Vruta::Routine > pattern(std::function< std::any(uint64_t)> pattern_func, std::function< void(std::any)> callback, std::function< bool(uint64_t)> ready, Vruta::ProcessingToken token)
The std::any, uint64_t form of the condition driven pattern.
Definition Pattern.cpp:5

Referenced by read_normalized_at().

Here is the caller graph for this function: