how to raise something to a power?

Non-platform specific questions.

how to raise something to a power?

Postby j2graves » Fri Nov 18, 2011 5:57 pm

Hey, I need to know how to raise something to a power in GE. :P
No games to my name...
User avatar
j2graves
 
Posts: 1302
Joined: Thu Aug 16, 2007 6:42 pm
Location: on the other side of infinity
Score: 19 Give a positive score

Re: how to raise something to a power?

Postby SuperSonic » Fri Nov 18, 2011 6:06 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: how to raise something to a power?

Postby j2graves » Fri Nov 18, 2011 6:54 pm

Thanks! +1
No games to my name...
User avatar
j2graves
 
Posts: 1302
Joined: Thu Aug 16, 2007 6:42 pm
Location: on the other side of infinity
Score: 19 Give a positive score

Re: how to raise something to a power?

Postby SuperSonic » Fri Nov 18, 2011 7:37 pm

j2graves wrote:Thanks! +1

Thank you^^
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: how to raise something to a power?

Postby skydereign » Fri Nov 18, 2011 9:09 pm

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
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: how to raise something to a power?

Postby SuperSonic » Fri Nov 18, 2011 10:25 pm

@Sky: I thought that the ^ worked in c++ :?
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: how to raise something to a power?

Postby skydereign » Fri Nov 18, 2011 11:42 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: how to raise something to a power?

Postby SuperSonic » Sat Nov 19, 2011 12:12 am

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: how to raise something to a power?

Postby j2graves » Sun Nov 20, 2011 1:48 pm

thanks Sky! + 1
No games to my name...
User avatar
j2graves
 
Posts: 1302
Joined: Thu Aug 16, 2007 6:42 pm
Location: on the other side of infinity
Score: 19 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest