Jump to content
  • Advertisement
Sign in to follow this  
sipickles

Powers in C++

This topic is 4772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am probably being dumb, but I thought ^ meant 'power of', as in 2 ^ 3 = 8. I always get 1 as an answer! I included cmath.h too! Please put me out my misery! Thanks Si

Share this post


Link to post
Share on other sites
Advertisement
In C++ ^ means bitwise XOR. To get powers you should use the pow() or powf() functions.

Share this post


Link to post
Share on other sites
^ is the Bitwise Exclusive OR.

you'll need to use a function.. like pow.

people often type ^ on a forum or in text as it does commonly refer to a power (on calculators definitely). But not in c++.

Share this post


Link to post
Share on other sites
Leaves one to question why we can't overload the operator to mean "raise to power". *sigh*.

Can't have everything I guess. Personally, I'd rather have XOR, AND, and OR be the operators.

Share this post


Link to post
Share on other sites
Quote:
Original post by ciroknight
Leaves one to question why we can't overload the operator to mean "raise to power". *sigh*.


Overload for which data types? And remember that overloading can't change operator priority or associativity.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!