0

is there a reason? i know there's POW(), but that's a function. why doesn't it have ^ for exponents, when it seems like a very simple thing too add, that would be very convenient

  • 2
    Why everyone is having problem with `pow` :P `^` is **bit-wise exclusive OR** – P0W Jan 27 '14 at 06:15
  • It's `pow`. POW would be a completely different thing (well, we can't be just things...). – Mark Garcia Jan 27 '14 at 06:15
  • Because they didn't put it in. You would have to ask Bjarne Stroustrup or the C++ committee, or Dennis Ritchie or the C committee. Anything you get here will be just more or less uninformed guesswork. – user207421 Jan 27 '14 at 06:17
  • Highly speculative: There was no built in FPU available at design time –  Jan 27 '14 at 06:20
  • @DieterLücking On the contrary. The PDP-11 had a full array of FP instructions, and ditto the VAX. – user207421 Jan 27 '14 at 06:23
  • It is explained in *The Design and Evolution of C++*, ch.11.6.1. "The original reason was that C doesn't have one..." and more. – SChepurin Jan 27 '14 at 07:21

2 Answers2

0

C++'s operators are modeled after C's operators which in turn are modeled after general machine code instructions. The later have addition, subtraction, shift, and , or , xor etc. They can have multiplication and perhaps even division. All handle integers are handled and sometimes even floating-point numbers too. But it would extremely rare for exponentiation to have direct processor support. So it's never been thought of as (and so therefore wasnever made into) a builtin operator. Having said all that, there's left-shift << which exponentiates powers of 2.

Paul Evans
  • 27,315
  • 3
  • 37
  • 54
  • It isn't 'extremely rare'. The most commonly used processor family has had such an instruction for decades. I was using it on the PDP-11 in the 1970s, which is what C was built on. – user207421 Jan 27 '14 at 06:28
-2

In some languages ^ is the sign of logical operation. I think is XOR operation.

So that is why you should use POW() in C++.

pb77
  • 47
  • 9