From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20078 invoked by alias); 2 Dec 2012 22:00:02 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17445 Received: (qmail 13426 invoked from network); 2 Dec 2012 22:00:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <121202135940.ZM19771@torch.brasslantern.com> Date: Sun, 02 Dec 2012 13:59:40 -0800 In-reply-to: Comments: In reply to Atom Smasher "$[ 09.5 ] -- bad math expression" (Dec 2, 11:30pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: $[ 09.5 ] -- bad math expression MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Dec 2, 11:30pm, Atom Smasher wrote: } } echo "$[ 09.5 ]" } zsh: bad math expression: operator expected at `.5 ' } } the problem seems to come up when using a non-integer with a leading } zero. Hmm. This appears to have changed back in about 2007, workers/23165. Any number with a leading zero is interpreted as an integer, unless a decimal point immediately follows the zero, in which case it's treated as floating point. } is this a known bug? I'd certainly never heard of it before. Looks like a logic error in adding the "else" clause at the very end of the math.c hunk of 23165. } are there any workarounds? Counterintuitively, you can fix this by "setopt octalzeroes". With that option set, the entire constant is checked for whether it forms a valid octal number, so then the presence of the decimal point forces it to be interpreted as floating point. However, that might have some unintended consequences on the rest of your script ... In the patch below I pulled the memchr from the original code that was changed by 23165. There may be a better way to do that test. Index: Src/math.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/math.c,v retrieving revision 1.43 diff -u -r1.43 math.c --- Src/math.c 11 Sep 2012 16:02:42 -0000 1.43 +++ Src/math.c 2 Dec 2012 21:46:50 -0000 @@ -447,7 +447,8 @@ if (*nptr == '-') nptr++; - if (*nptr == '0') + if (*nptr == '0' && + (memchr(nptr, '.', strlen(nptr)) == NULL)) { nptr++; if (*nptr == 'x' || *nptr == 'X') { Index: Test/C01arith.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/C01arith.ztst,v retrieving revision 1.19 diff -u -r1.19 C01arith.ztst --- Test/C01arith.ztst 11 Sep 2012 16:02:42 -0000 1.19 +++ Test/C01arith.ztst 2 Dec 2012 21:57:29 -0000 @@ -152,6 +152,16 @@ 0:commas and parentheses, part 1 >4 + print $(( 07.5 )) + (setopt octalzeroes; print $(( 09.5 ))) +0:leading zero doesn't affect floating point +>7.5 +>9.5 + + (setopt octalzeroes; print $(( 09 ))) +1:octalzeroes rejects invalid constants +?(eval):1: bad math expression: operator expected at `9 ' + (setopt octalzeroes; print $(( 08#77 ))) 0:octalzeroes doesn't affect bases >63