SA-MP Forums Archive
do floatmul/div really needed? - 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)
+--- Thread: do floatmul/div really needed? (/showthread.php?tid=489194)



do floatmul/div really needed? - newbienoob - 21.01.2014

I only tested with floatmul
pawn Код:
main()
{
    new Float:x = 23.0, Float:y = 21.0, Float:z = 45.1, Float:x1 = 45.2, Float:y1 = 68.1, Float:z1 = 28.5;
    x1 = x + floatmul(x1, 5); //with floatmul
    y1 = y + floatmul(y1, 5);
    z1 = z + floatmul(z1, 5);
    printf("%f, %f, %f", x1,y1,z1);
   
    new Float:xa = 23.0, Float:ya = 21.0, Float:za = 45.1, Float:xb = 45.2, Float:yb = 68.1, Float:zb = 28.5;
    xb = xa + xb * 5; //without floatmul
    yb = ya + yb * 5;
    zb = za + zb * 5;
    printf("%f, %f, %f", xb,yb,zb);
}
Prints:
249.000000, 361.500000, 187.600006
249.000000, 361.500000, 187.600006

Same results. So are they really needed?


Re: do floatmul/div really needed? - Vince - 21.01.2014

No, you can use the standard operators. The standard operators are overloaded to call these respective functions. Using the functions might be marginally faster, but they don't improve readability.

In float.inc:
pawn Код:
stock Float:operator*(Float:oper1, oper2)
    return floatmul(oper1, float(oper2));       /* "*" is commutative */



Re: do floatmul/div really needed? - newbienoob - 21.01.2014

So... using the functions are just slightly faster than the standard one?


AW: do floatmul/div really needed? - BigETI - 21.01.2014

The use of the functions are to overload the operators, to support floating point operations in PAWN.