MCPcopy Create free account
hub / github.com/Autodesk/Aurora / floatToHalf

Function floatToHalf

Tests/Helpers/TestHelpers.cpp:147–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147uint16_t floatToHalf(const float x)
148{ // IEEE-754 16-bit floating-point format (without infinity): 1-5-10, exp-15, +-131008.0,
149 // +-6.1035156E-5, +-5.9604645E-8, 3.311 digits
150 const uint32_t b =
151 as_uint(x) + 0x00001000; // round-to-nearest-even: add last bit after truncated mantissa
152 const uint32_t e = (b & 0x7F800000) >> 23; // exponent
153 const uint32_t m =
154 b & 0x007FFFFF; // mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 =
155 // decimal indicator flag - initial rounding
156 return static_cast<uint16_t>((b & 0x80000000) >> 16 |
157 (e > 112) * ((((e - 112) << 10) & 0x7C00) | m >> 13) |
158 ((e < 113) & (e > 101)) * ((((0x007FF000 + m) >> (125 - e)) + 1) >> 1) |
159 (e > 143) * 0x7FFF); // sign : normalized : denormalized : saturate
160}
161
162float createFloat32(uint32_t mantisa, uint32_t exponent, uint32_t sign)
163{

Callers

nothing calls this directly

Calls 1

as_uintFunction · 0.85

Tested by

no test coverage detected