Pow operator precedence

Matej Nanut matejnanut at gmail.com
Fri Jan 13 09:41:29 PST 2012


I feel it should be left as is: it'll be ambiguous either way and why mess
with how it's in mathematics? If anyone feels uncomfortable using it,
just use std.math.pow. Many other languages don't have this operator so
people coming from them won't know it exists anyway (like me until this
post).

— Matej

On 13 January 2012 18:01, Mehrdad <wfunction at hotmail.com> wrote:
> On 1/13/2012 8:59 AM, Mehrdad wrote:
>>
>> On 1/13/2012 4:48 AM, bearophile wrote:
>>>
>>> This is the third time I see people trip on power operator precedence:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=7268
>>>
>>> Some people expect this:
>>> (-10 ^^ 2)
>>> To be 100 instead of -100
>>> (Note: Python here uses the same operator precedences.)
>>>
>>> Do you think it's worth (and possible) to help D programmers avoid this
>>> mistake in their code?
>>>
>>> Bye,
>>> bearophile
>>
>>
>> I don't like it, but I think we should keep it.
>>
>> The reason?
>>
>> -10 ^^ 2 == -(10) ^^ 2 == -(x) ^^ 2 == -x ^^ 2 != (-x) ^^ 2
>
> Heck, or how about emitting a warning if it's a literal without parentheses
> either way?


More information about the Digitalmars-d mailing list