Alex Rivera | Logout

Why does C++ not have an exponentiation operator?

Asked 2010-09-23T03:24:10.957
30

I am taking a class in C++ and I noticed there are only a few math operators to use. I also noticed that C++ does not come with an exponential operator within its math library.

Why must one always write a function for this? Is there a reason for the makers of C++ to omit this operator?

Edit
Report

1 Answer

63

You don't write a function for this (unless you're insane, of course). There's a perfectly good pow function defined in the <cmath> header.

Aside: if you try to use ^ as a power operator, as some people are wont to do, you'll be in for a nasty surprise. It's the exclusive-or (XOR) operator (see here).

answered 2010-09-23T03:27:35.903

Your Answer