a**b exponentiation

Deewiant deewiant.doesnotlike.spam at gmail.com
Fri Jun 29 11:23:09 PDT 2007


Stephen Montgomery-Smith wrote:
> 1. Put in an exponentiation operator, a^b or a**b, so that 2**3 is 8.
> For a numerics programmer this would be really useful. This is one way
> that Fortran really scores over C. I know that there is the pow function
> in C, but it always treats the power as a float or double, where if the
> power is an integer it should really work differently. Also the
> optimization should be able to do clever things with a^2 (i.e. write it
> as inline code a*a). Also, using "pow" is just plain ugly. I do
> appreciate that a^b and a**b already have meaning in C (the first is
> exclusive or, and the second is a*(*b)), but I think that this is
> sufficiently worthwhile for numerics programmers that you either find a
> whole new symbol, or depreciate the current use of ^ or ** (e.g. one
> could insist that the current a**b is always written a* *b - I mean when
> does a**b actually ever appear in real code?).

We have precedent for the problem of a**b: we already have ++a and a++, both of
which can lead to similar problems. What does "a+++b" mean? Possibilities are
"a++ + b" and "a + ++b". Also, "a++b" can be "a + +b", but parses as "a++ b", a
syntax error.

-- 
Remove ".doesnotlike.spam" from the mail address.



More information about the Digitalmars-d mailing list