Does pow(k,4) more cheap than kkk*k ?
I honestly doubt it.
Apparently pow(x,y) becomes exp(y * log(x)).
As exp and log are directly implemented as ALUs it’s probably the same to use pow() - and neater to read?
giving log, multiply and exp for pow()
and multiply, multiply and multiply for multiplying
Honestly I’m not sure you’d even notice. Depends on the platform and how smart the compiler is…
I also think it’s easier to spot a typo in pow(someValue,4) than in someValue * someValue * someVaIue * someValue. So it’s cheaper at time of development.
No, I’m just failing to count ![]()
On mobile, the pow would be significantly slower, so if in doubt, go with the multiply.
On fast desktop GPUs, there’s probably no observable difference - “math operations are almost free there”. Raising to power is roughly an exponent, logarithm and a multiply like others have said. Manually raising something to 4th power is two multiplies. The latter is probably faster, but if the driver is smart enough, it might very well just recognize this and do the optimization internally.
On slow desktop GPUs, and on mobile, the situation might be different. Specifically on mobile, the drivers are rarely smart
In case of raising to 4th power, I’d go with two multiplies instead.
x *= x;
x *= x;