Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: negative bases in arithmetic expressions
- X-seq: zsh-workers 43261
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: negative bases in arithmetic expressions
- Date: Wed, 8 Aug 2018 17:05:34 +0100
- Cms-type: 201P
- Dkim-filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180808160538euoutp02b1bb00a4dd6035320c51d4cc4653dc47~I9FlrFeZL1783917839euoutp02N
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1533744338; bh=zIW5RdQjofkm4j0QzCasn9S8wSqKsq+Nduf7VXQn+OQ=; h=Date:From:To:Subject:In-Reply-To:References:From; b=MJsAPBnxCkHgTXHUigOW7AXNLqFzlYe8/BCDV+PAprKNEK0LFSCDXjf1uAGE6JJ3G 6SBNteo6LYWIL/5u/LU9tmLftFTT1DAAdYujMx/+YxUbK99WmmyFPtGzahMhgVpNLf ZJ4TfJ+FKUr9O8OfV6Ucm3ShVFyX0yuhWxgSfKwQ=
- In-reply-to: <20180808153706.GB16265@chaz.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: SCSC
- References: <CGME20180808153741epcas3p346a9ba58cddb7bd5d5e91aaf3a63d51c@epcas3p3.samsung.com> <20180808153706.GB16265@chaz.gmail.com>
On Wed, 8 Aug 2018 16:37:06 +0100
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> $ zsh -c 'echo $((-8#10))'
> zsh:1: invalid base (must be 2 to 36 inclusive): -8
> $ zsh -c 'echo $((- 8#10))'
> -8
>
> I'd rather zsh interpreted $((-8#10)) the same as $((- 8#10))
> like other shells do as it's a bit pointless to consider the
> sign as being part of the base and then reject anything negative
> afterwise.
No real argument there, I don't think.
pws
diff --git a/Src/math.c b/Src/math.c
index 4b7ecf0..b08e05c 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -640,8 +640,19 @@ zzlex(void)
}
if (unary) {
if (idigit(*ptr) || *ptr == '.') {
- ptr--;
- return lexconstant();
+ int ctype = lexconstant();
+ if (ctype == NUM)
+ {
+ if (yyval.type == MN_FLOAT)
+ {
+ yyval.u.d = -yyval.u.d;
+ }
+ else
+ {
+ yyval.u.l = -yyval.u.l;
+ }
+ }
+ return ctype;
} else
return UMINUS;
} else
diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index 77a46eb..f1364ab 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -467,3 +467,7 @@
>6
>4
?(eval):6: bad math expression: lvalue required
+
+ print $(( -2#101-16#f ))
+0: Unary minus doesn't apply to base but to number as a whole.
+>-20
Messages sorted by:
Reverse Date,
Date,
Thread,
Author