SA-MP Power of a number.
#1

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);
Reply
#2

pawn Код:
floatint(floatpower(float(x),2)*10);
Reply
#3

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);
Reply
#4

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

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)