Page 1 of 1

how to raise something to a power?

PostPosted: Fri Nov 18, 2011 5:57 pm
by j2graves
Hey, I need to know how to raise something to a power in GE. :P

Re: how to raise something to a power?

PostPosted: Fri Nov 18, 2011 6:06 pm
by SuperSonic
Use the carrot oporator (^)
For example, to raise 2 to the fourth power, you can do this:
2^4
It also works with variables:
x^4
Hope that helped :D

Re: how to raise something to a power?

PostPosted: Fri Nov 18, 2011 6:54 pm
by j2graves
Thanks! +1

Re: how to raise something to a power?

PostPosted: Fri Nov 18, 2011 7:37 pm
by SuperSonic
j2graves wrote:Thanks! +1

Thank you^^

Re: how to raise something to a power?

PostPosted: Fri Nov 18, 2011 9:09 pm
by skydereign
You have to use the pow function. ^ is the bitwise exclusive or operator (something you most likely won't use, and will not have the same effect).
Code: Select all
int value = pow(5,2); // = 25

Re: how to raise something to a power?

PostPosted: Fri Nov 18, 2011 10:25 pm
by SuperSonic
@Sky: I thought that the ^ worked in c++ :?

Re: how to raise something to a power?

PostPosted: Fri Nov 18, 2011 11:42 pm
by skydereign
You can definitely overwrite ^ to do exponents, but by default it should be set to bitwise xor. Also, since C++ and C should be compatible in most cases, switching the use of ^ by default would have been a bad idea.

Re: how to raise something to a power?

PostPosted: Sat Nov 19, 2011 12:12 am
by SuperSonic
skydereign wrote:You can definitely overwrite ^ to do exponents, but by default it should be set to bitwise xor. Also, since C++ and C should be compatible in most cases, switching the use of ^ by default would have been a bad idea.

Ok, thanks for explaining that to me :D

Re: how to raise something to a power?

PostPosted: Sun Nov 20, 2011 1:48 pm
by j2graves
thanks Sky! + 1