Floatpower vs float*float
#1

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.
Reply
#2

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
Reply
#3

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 */
Reply
#4

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


Forum Jump:


Users browsing this thread: 2 Guest(s)