07.12.2016, 19:06
It took me a while to figure out how the last part of the floating-point number works:
The only difference between mine and yours (in results) is that fractional 0.0 will give 11111111 (255) for you while mine will stay at 0.
pawn Код:
f2b(Float: f)
{
new Float: fractional = floatfract(f), fract, binary[20];
for (new i; i != 8; i++)
{
if((fractional *= 2.0) > 1.0)
{
fractional -= 1.0;
if (!fract) fract = 1;
else fract = fract * 2 + 1;
}
else
{
if (fract) fract *= 2;
}
}
format(binary, sizeof binary, "%b.%b", floatround(f, floatround_floor), fract);
return binary;
}