SA-MP Forums Archive
What about this commands? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: What about this commands? (/showthread.php?tid=617197)

Pages: 1 2


Re: What about this commands? - Konstantinos - 07.12.2016

It took me a while to figure out how the last part of the floating-point number works:
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;
}
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.