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?
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).
According to Bjarne Stroustrup in his book The design and evolution of C++. They decided to avoid exponential operator because :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With