More on semantics of opPow: return type

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Dec 7 11:59:04 PST 2009


Lars T. Kyllingstad wrote:
> Andrei Alexandrescu wrote:
>> Nice analysis. IMHO this should lead us to reconsider the necessity of 
>> "^^" in the first place. It seems to be adding too little real value 
>> compared to the complexity of defining it.
>>
>> Andrei
> 
> 
> It adds a lot of value to the ones that actually use it, even though you 
> may not be one of them. Exponentiation is extremely common in numerics.

Well I write numerics and I do use exponentiation occasionally, but 
never to the extent of yearning for ^^. "Extremely common" would be, I 
think, quite difficult to argue.

> Here are some statistics for you: A Google code search (see below) for 
> FORTRAN code using the power operator **, which until recently didn't 
> have a D equivalent, yields roughly 56100 results.
> 
> A search for the FORTRAN equivalents of << yield 400 results for ILS() 
> and 276 results for LSHIFT(). Yet, left shift apparently deserves a 
> place in D.
> 
> 
> (I've used http://www.google.com/codesearch, with the following search 
> strings for **, ILS and LSHIFT, respectively:
> 
>     [0-9a-zA-Z)]\*\*[0-9a-zA-Z(] lang:fortran
>     ils\([0-9a-zA-Z] lang:fortran
>     lshift\([0-9a-zA-Z] lang:fortran
> 
> As statistics go, this is probably not a prime example, but it is at 
> least an indication.)

Thanks for collecting the evidence. To make it more meaningful, you may 
want to report it to the total number of lines of code searched. I don't 
know how to do that with codesearch.

FWIW, this search:

[0-9a-zA-Z)]\*\*[013456789a-zA-Z(] lang:fortran

yields 30,300 results, meaning that almost half the uses of 
exponentiation is to square things.

So I'm not sure what this all is supposed to argue for or against. What 
I can say is that Don's analysis suggested to me, let's leave all that 
aggravation to overloads of pow() and call it a day. I was much more in 
favor of ^^ before I saw how quickly it gets complicated. That kind of 
stuff just doesn't strike me as the kind of things you put straight in 
the core language.


Andrei



More information about the Digitalmars-d mailing list