a**b exponentiation

Stephen Montgomery-Smith stephen at math.missouri.edu
Mon Jul 2 17:38:15 PDT 2007


Chris Nicholson-Sauls wrote:
> Deewiant wrote:
>> 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.
>>
> 
> This is at least predictable because of the compiler's "maximal munch" 
> policy: always grab the biggest hunk of source you can at one time.(The 
> 'a+++b' example would parse as 'a++ +b'.)
> 
> And I rather like the other proposed operator: ^^
> Should be more clear, and more familiar since some languages already use 
> '^' to mean power -- so long as it doesn't get confused with our 
> existing '^' operator...

I also like "^^", but "**" does have some history - I think it is used 
in FORTRAN.



More information about the Digitalmars-d mailing list