SA-MP Forums Archive
Floatpower vs float*float - 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: Floatpower vs float*float (/showthread.php?tid=414327)



Floatpower vs float*float - lavamike - 09.02.2013

Is there a difference between using Floatpower vs multiplying the floats by eachother?

Example:
pawn Код:
new Float:X;
X = 5.3423;
X = floatround(floatpower(X, 2)); // This or
X = floatround((X * X)); // this
Are they exactly the same, is floatpower slower because it has to call a function or something? Any info would be appreciated, thanks.


Respuesta: Floatpower vs float*float - TheChaoz - 09.02.2013

Ok so after running a simple speed test it looks like that floatpower in fact is much more slower than the multiply method:
pawn Код:
#include <a_samp>

public OnFilterScriptInit()
{
    new Float:X = 3.5, Float:res;
    new time = GetTickCount();
    for(new i; i<10000000; i++)
        res = X*X;
    printf("Multiply time: %ims", GetTickCount()-time);
    time = GetTickCount();
    for(new i; i<10000000; i++)
        res = floatpower(X, 2);
    printf("floatpower time: %ims", GetTickCount()-time);
    return 1;
}
Results:
Код:
Multiply time: 680ms
floatpower time: 2109



Re: Floatpower vs float*float - Vince - 09.02.2013

I wonder why that is, because this is found in float.inc:
pawn Код:
stock Float:operator*(Float:oper1, oper2)
    return floatmul(oper1, float(oper2));       /* "*" is commutative */



Re: Floatpower vs float*float - lavamike - 10.02.2013

That's quite interesting actually, thanks for the info. I also kinda wonder why that is as well, seems strange.