| 273 | } |
| 274 | |
| 275 | float halfToFloat(std::uint16_t value) |
| 276 | { |
| 277 | // IEEE-754 16-bit floating-point format (without infinity): 1-5-10, exp-15, +-131008.0, +-6.1035156E-5, +-5.9604645E-8, 3.311 digits |
| 278 | const std::uint32_t e = (value & 0x7C00) >> 10; // Exponent |
| 279 | const std::uint32_t m = (value & 0x03FF) << 13; // Mantissa |
| 280 | const std::uint32_t v = as_uint32((float)m) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format |
| 281 | return as_float((value & 0x8000) << 16 | (e != 0) * ((e + 112) << 23 | m) | ((e == 0) & (m != 0)) * ((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000))); // sign : normalized : denormalized |
| 282 | } |
| 283 | |
| 284 | std::uint16_t floatToHalf(float value) |
| 285 | { |
no test coverage detected