Sujet : Re: Operator precedence
De : mail (at) *nospam* axel-reichert.de (Axel Reichert)
Groupes : comp.lang.awkDate : 25. May 2024, 12:34:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87zfsektvi.fsf@axel-reichert.de>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Kaz Kylheku <
643-408-1753@kylheku.com> writes:
Now in the C grammar, we have multiplication also occuping a
precedence rung between unary plus/minus and additive expressions.
>
Thus -A*B means (-A)*B, whereas X - A*B means X-(A*B).
>
In this case it doesn't matter because the unary minus is
a kind of product. -A can be regarded as a shorthand for (-1)*A.
>
More importantly the identity (-A)*B = -(A*B) holds.
>
This creates a problem if we naively wedge exponentiation into
the grammar, by sticking it into a precedence level above
multiplication, but below unary.
>
The identity does not hold in exponentiation: (-A)**B
is not -(A**B).
Very nice explanation, many thanks. I will likely pass it to a friend
(geodesist), who had a heated argument with the math teacher of her son
about whether
2
-3
is -9 or +9. I think the mathematical conventions are clear (and
probably established for centuries), but the teacher might be confused
and think Excel is the reference, see
https://en.wikipedia.org/wiki/Order_of_operations#Unary_minus_signIt would be interesting to learn about the motivation for spreadsheets
and "bc" to deviate from the mathematical convention.
Best regards
Axel