bearophile wrote:
Don:
so there's nothing else you'd want to use ^^ for.
People would get used to it pretty quickly. I think it looks better than
Fortran's **, actually. double y = x^^2;
I have asked for a power operator lot of time ago, in one of my first long
lists of suggestions.
^^ isn't standard in other languages (they usually use ** or ^), but it looks
nice enough, and it doesn't look hard to understand or learn.
I'd like it to perform integral exponentiation if both operands are integral,
and double/real exponentiation in the other cases.
In mathematics ^^ is sometimes used for Tetration, but it's not a problem, it's
not a common operation:
http://en.wikipedia.org/wiki/Tetration
So this looks like a good idea.
The front-end *must* be able to translate x ^^ 2 and x ^^ 3 into x*x and x*x*x,
that are faster than any other kind of operation (Python doesn't do this simple
operation, and a power operation done in the middle of a critical loop can slow
down the code, I have seen this in my Python code).
(x ^^ 4 can be simplified into y = x*x; y*y, but this is a less common
operation).
I guess the way to overload this operator is named opPower(). So for example if
A is a user-defined matrix you can write:
auto B = A ^^ 2;
Bye,
bearophile
This deserves its own thread. I'll create one.
-Lars