Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: arithmetic operator precedence
- X-seq: zsh-workers 25214
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: arithmetic operator precedence
- Date: Thu, 19 Jun 2008 10:58:07 +0100
- In-reply-to: <a0600102dc47fd2c6184e@xxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20080612095723.GF5113@xxxxxxxxxxxxxxx> <20080616080726.GP10734@xxxxxxxxxxxxxxxxxxx> <20080616144211.276fb0e3@pws-pc> <2d460de70806170219k12ff4cadn441b52c48bf8076f@xxxxxxxxxxxxxx> <20080617094509.GC5016@xxxxxxxxxxxxxxx> <2d460de70806170324o5a44609x9383cc2445d67dd6@xxxxxxxxxxxxxx> <20080617103829.GD5016@xxxxxxxxxxxxxxx> <20080617114340.398c731f@news01> <20080617112815.GF10734@xxxxxxxxxxxxxxxxxxx> <200806171146.m5HBkhfR013230@xxxxxxxxxxxxxx> <a0600102dc47fd2c6184e@xxxxxxxxxxxxxxxxx>
"Jun T." wrote:
> I think it would be sufficient to add to the man page something like
> "-3**2 gives 9, not -9, in zsh and many other shells.
> Be sure to use parentheses -(3**2) if you want -9."
That seems a good idea in any case.
Index: Doc/Zsh/arith.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/arith.yo,v
retrieving revision 1.13
diff -u -r1.13 arith.yo
--- Doc/Zsh/arith.yo 12 Jun 2008 13:45:05 -0000 1.13
+++ Doc/Zsh/arith.yo 19 Jun 2008 09:56:13 -0000
@@ -93,8 +93,9 @@
cindex(operators, arithmetic)
An arithmetic expression uses nearly the same syntax and
associativity of expressions as in C.
-The following operators are supported (listed in decreasing order
-of precedence):
+
+In the native mode of operation, the following operators are supported
+(listed in decreasing order of precedence):
startsitem()
sitem(tt(PLUS() - ! ~ PLUS()PLUS() --))(unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement)
@@ -142,6 +143,10 @@
sitem(tt(,))(comma operator)
endsitem()
+Note the precedence of exponentiation in both cases is below
+that of unary operators, hence `tt(-3**2)' evaluates as `tt(9)', not
+tt(-9). Use parentheses where necessary: `tt(-(3**2))'.
+
cindex(mathematical functions, use of)
cindex(functions, math, use of)
Mathematical functions can be called with the syntax
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author