summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Src/math.c15
-rw-r--r--Test/C01arith.ztst4
3 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7a4cb05a2..28f70f48a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-08-08 Peter Stephenson <p.stephenson@samsung.com>
+
+ * 43261: Src/math.c, Test/C01arith.ztst: Apply unary minus to
+ entire lexical constant, so base doesn't get treated as negative.
+
2018-08-07 Peter Stephenson <p.stephenson@samsung.com>
* Anton Shestakov: 43254: Completion/Unix/Command/_hg: Remove hg
diff --git a/Src/math.c b/Src/math.c
index 4b7ecf0ab..b08e05cb4 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 77a46ebd5..f1364ab36 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