MCPcopy Create free account
hub / github.com/numpy/numpy / ToFloatBits

Function ToFloatBits

numpy/core/src/common/half_private.hpp:269–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269constexpr uint32_t ToFloatBits(uint16_t h)
270{
271 uint16_t h_exp = (h&0x7c00u);
272 uint32_t f_sgn = ((uint32_t)h&0x8000u) << 16;
273 switch (h_exp) {
274 case 0x0000u: { // 0 or subnormal
275 uint16_t h_sig = (h&0x03ffu);
276 // Signed zero
277 if (h_sig == 0) {
278 return f_sgn;
279 }
280 // Subnormal
281 h_sig <<= 1;
282 while ((h_sig&0x0400u) == 0) {
283 h_sig <<= 1;
284 h_exp++;
285 }
286 uint32_t f_exp = ((uint32_t)(127 - 15 - h_exp)) << 23;
287 uint32_t f_sig = ((uint32_t)(h_sig&0x03ffu)) << 13;
288 return f_sgn + f_exp + f_sig;
289 }
290 case 0x7c00u: // inf or NaN
291 // All-ones exponent and a copy of the significand
292 return f_sgn + 0x7f800000u + (((uint32_t)(h&0x03ffu)) << 13);
293 default: // normalized
294 // Just need to adjust the exponent and shift
295 return f_sgn + (((uint32_t)(h&0x7fffu) + 0x1c000u) << 13);
296 }
297}
298
299constexpr uint64_t ToDoubleBits(uint16_t h)
300{

Callers 2

HalfClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected