opPow, opDollar

Bill Baxter wbaxter at gmail.com
Sun Nov 8 07:39:06 PST 2009


On Sat, Nov 7, 2009 at 2:43 AM, Don <nospam at nospam.com> wrote:
> Walter Bright wrote:
>>
>> Don wrote:
>>>
>>> A little while ago I said I'd create a patch for ^^ as an exponentiation.
>>> A couple of people had requested that I make a post to the ng so they'd know
>>> when it happens. Here it is.
>>>
>>> This is opPow(),  x ^^ y
>>>
>>> http://d.puremagic.com/issues/show_bug.cgi?id=3481
>>
>> I don't understand the rationale for an exponentiation operator. It isn't
>> optimization, because pow() could become an intrinsic that the compiler
>> knows about. pow() is well known, ^^ isn't. (Fortran uses **)

Yes, pow() is a well-known annoyance in languages that don't have an
exponentiation operator. :-)


> It's primarily about syntax sugar: pow() is so ugly. In practice, the most
> important case is squaring, which is an extremely common operation.
> pow(xxx,2) is horribly ugly for something so fundamental. It's so ugly that
> noone uses it: you always change it to xxx * xxx. But then, xxx gets
> evaluated twice.

xxx also has to be typed twice.  Cubes also appear fairly often.

> Yes, ^^ hasn't been used for exponentiation before. Fortran used ** because
> it had such a limited character set, but it's not really a natural choice;
> the more mathematically-oriented languages use ^. Obviously C-family
> languages don't have that possibility.

I think ^^ is a fine choice.  This is great for folks who do a lot of
numerical stuff.

--bb



More information about the Digitalmars-d mailing list