Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: arithmetic operator precedence
- X-seq: zsh-workers 25196
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>, Richard Hartmann <richih.mailinglist@xxxxxxxxx>, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Subject: Re: arithmetic operator precedence
- Date: Tue, 17 Jun 2008 15:35:59 +0100
- In-reply-to: <20080617132039.GK5016@xxxxxxxxxxxxxxx>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxxxxx>, Richard Hartmann <richih.mailinglist@xxxxxxxxx>, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20080616080726.GP10734@xxxxxxxxxxxxxxxxxxx> <20080616144211.276fb0e3@pws-pc> <2d460de70806170219k12ff4cadn441b52c48bf8076f@xxxxxxxxxxxxxx> <20080617094509.GC5016@xxxxxxxxxxxxxxx> <20080617111934.GE10734@xxxxxxxxxxxxxxxxxxx> <20080617115742.GE5016@xxxxxxxxxxxxxxx> <20080617123551.GJ10734@xxxxxxxxxxxxxxxxxxx> <20080617124607.GH5016@xxxxxxxxxxxxxxx> <20080617130246.GL10734@xxxxxxxxxxxxxxxxxxx> <20080617132039.GK5016@xxxxxxxxxxxxxxx>
On Tue, Jun 17, 2008 at 02:20:39PM +0100, Stephane Chazelas wrote:
> On Tue, Jun 17, 2008 at 03:02:46PM +0200, Vincent Lefevre wrote:
> [...]
> > It is unspecified. So, the shell is right to choose how it sees it.
> >
> > > If $a contains an integer constant such as -3, then as per
> > > POSIX, $((a * 3)) should be the same as $(($a * 3)), that is
> > > $((-3 * 3)).
> >
> > No, POSIX does not say that. It happens to be the same thing here
> > just because of the properties of *, but you can't deduce anything
> > for extensions.
>
> It says $((x)) is meant to be the same as $(($x)) which I
> understand as any occurrance of a variable name (other than $-,
> $?, $0... obviously) in $((...)) should be the same as if the $
> was not ommited (when $x contains an integer constant).
[...]
It can't be that simple though, as in
x=-1; $((1 x))
which would be POSIX but fails in all shells.
Or
x=1; $((x = 1 + x))
which obviously is not meant to be the same as $(($x = 1 + $x))
So that
If the shell variable x contains a value that forms a valid
integer constant, then the arithmetic expansions "$((x))" and
"$(($x))" shall return the same value.
says either too little or too much to be useful.
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author