MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / halfToFloat

Function halfToFloat

Sources/nCine/Base/Algorithms.cpp:275–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 1

MpLevelHandler.cppFile · 0.85

Calls 2

as_uint32Function · 0.85
as_floatFunction · 0.85

Tested by

no test coverage detected