IO-AIO
view release on metacpan or search on metacpan
libeio/ecb.h view on Meta::CPAN
ecb_function_ ecb_const uint32_t ecb_binary16_to_binary32 (uint32_t x);
ecb_function_ ecb_const uint32_t
ecb_binary16_to_binary32 (uint32_t x)
{
unsigned int s = (x & 0x8000) << (31 - 15);
int e = (x >> 10) & 0x001f;
unsigned int m = x & 0x03ff;
if (ecb_expect_false (e == 31))
/* infinity or NaN */
e = 255 - (127 - 15);
else if (ecb_expect_false (!e))
{
if (ecb_expect_true (!m))
/* zero, handled by code below by forcing e to 0 */
e = 0 - (127 - 15);
else
{
/* subnormal, renormalise */
unsigned int s = 10 - ecb_ld32 (m);
libeio/ecb.h view on Meta::CPAN
unsigned int half = (1 << (bits - 1)) - 1;
unsigned int even = (m >> bits) & 1;
/* if this overflows, we will end up with a normalised number */
m = (m + half + even) >> bits;
}
return s | m;
}
/* handle NaNs, preserve leftmost nan bits, but make sure we don't turn them into infinities */
m >>= 13;
return s | 0x7c00 | m | !m;
}
/*******************************************************************************/
/* fast integer to ascii */
/*
* This code is pretty complicated because it is general. The idea behind it,
( run in 0.387 second using v1.01-cache-2.11-cpan-05444aca049 )