Deutsch   English   Français   Italiano  
<87zfsektvi.fsf@axel-reichert.de>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Axel Reichert <mail@axel-reichert.de>
Newsgroups: comp.lang.awk
Subject: Re: Operator precedence
Date: Sat, 25 May 2024 13:34:25 +0200
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <87zfsektvi.fsf@axel-reichert.de>
References: <v2nium$1pl8f$1@dont-email.me> <20240523092856.646@kylheku.com>
	<87sey8movv.fsf@axel-reichert.de> <v2okuh$1vrvh$1@dont-email.me>
	<v2ouo9$2547f$1@dont-email.me> <20240523210755.307@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sat, 25 May 2024 13:34:28 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="95b7e16f1d4fa77bacc3c686b99317af";
	logging-data="3012821"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/kERiTRSAd9hLrHiDHW1qtzZOkT73n0OI="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:W0E3EcrqKCp6+ITEnx/RmCYVdrw=
	sha1:2gBVw9U7AIleYg/tURnciuV9hSg=
Bytes: 2336

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_sign

It would be interesting to learn about the motivation for spreadsheets
and "bc" to deviate from the mathematical convention.

Best regards

Axel