SA-MP Power of a number. - 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: SA-MP Power of a number. (
/showthread.php?tid=624720)
SA-MP Power of a number. -
AroseKhanNiazi - 21.12.2016
How do i calculate a power of x number in pawno? using ^ doesn't work.
This gives some odd kind of results. I am trying something like (x^2)*10.
It should have give these
x=1 - 10.
x=2 - 40.
x=3 - 90.
But instead it gives
x=1 - 30
x=2 - 0
x=3 - 10
This looks like '^' is acting as -2.
Code I used to test it
Код:
printf("%d",(1^2)*10);
printf("%d",(2^2)*10);
printf("%d",(3^2)*10);
Re: SA-MP Power of a number. -
Jochemd - 21.12.2016
pawn Код:
floatint(floatpower(float(x),2)*10);
Re: SA-MP Power of a number. -
Konstantinos - 21.12.2016
There's no reason to convert to float and back to integer:
pawn Код:
#define power_of_2(%0) (%0 * %0)
...
new x = 3;
printf("%i", power_of_2(x) * 10);
Re: SA-MP Power of a number. -
Vince - 21.12.2016
Quote:
Originally Posted by AroseKhanNiazi
using ^ doesn't work.
|
That's bitwise XOR, i.e. turn on the bit in the result if either, but not both, of the operands has the bit turned on.
Re: SA-MP Power of a number. -
AroseKhanNiazi - 21.12.2016
Thanks!