public static uint HalfToFloatI( ushort y )
{
uint yuint = (uint)y;
uint s = ( yuint >> 15 ) & 0x00000001;
uint e = ( yuint >> 10 ) & 0x0000001f;
uint m = yuint & 0x000003ff;
if ( e == 0 )
{
if ( m == 0 ) // Plus or minus zero
return ( s << 31 );
else
{ // Denormalized number -- renormalize it
while ( ( m & 0x00000400 ) == 0 )
{
m <<= 1;
e -= 1;
}
e += 1;
m &= 0xFFFFFBFF; // ~0x00000400;
}
}
else if ( e == 31 )
{
if ( m == 0 ) // Inf
return ( s << 31 ) | 0x7f800000;
else // NaN
return ( s << 31 ) | 0x7f800000 | ( m << 13 );
}
e = e + ( 127 - 15 );
m = m << 13;
return ( s << 31 ) | ( e << 23 ) | m;
}