Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: $[ 09.5 ] -- bad math expression



On Sun, 2 Dec 2012 23:30:34 +1300 (NZDT)
Atom Smasher <atom@xxxxxxxxxxx> wrote:
> with zsh 4.2.1 i get what i'd expect here:
> 
>  	echo "$[ 09.5 ]"
>  	9.5
> 
> and all math operations work as expected. with zsh 4.3.10, this is broken:
> 
>  	echo "$[ 09.5 ]"
>  	zsh: bad math expression: operator expected at `.5 '

Oops.

OCTAL_ZEROES looks a bit broken, too.  Good job no one uses it.

Index: Src/math.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/math.c,v
retrieving revision 1.43
diff -p -u -r1.43 math.c
--- Src/math.c	11 Sep 2012 16:02:42 -0000	1.43
+++ Src/math.c	2 Dec 2012 21:02:25 -0000
@@ -476,14 +476,11 @@ lexconstant(void)
 		lastbase = 8;
 		return NUM;
 	    }
-	    nptr = ptr2;
 	}
     }
-    else
-    {
-	while (idigit(*nptr) || *nptr == '_')
-	    nptr++;
-    }
+
+    while (idigit(*nptr) || *nptr == '_')
+	nptr++;
 
     if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') {
 	char *ptr2;
Index: Test/C01arith.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C01arith.ztst,v
retrieving revision 1.19
diff -p -u -r1.19 C01arith.ztst
--- Test/C01arith.ztst	11 Sep 2012 16:02:42 -0000	1.19
+++ Test/C01arith.ztst	2 Dec 2012 21:02:25 -0000
@@ -233,3 +233,8 @@
 >6000000
 >5000
 >255
+
+  # 3/4 is a multiple of power of two so assume it's represented exactly.
+  print ${$(( 09.75 * 4))%%.*}
+0:leading underscores
+>39



Messages sorted by: Reverse Date, Date, Thread, Author