From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14087 invoked by alias); 14 Nov 2013 11:30:56 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31982 Received: (qmail 364 invoked from network); 14 Nov 2013 11:30:50 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7fe66d00000432e-da-5284b4674c0d Date: Thu, 14 Nov 2013 11:30:45 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: $[ 09.5 ] -- bad math expression Message-id: <20131114113045.6bf509fc@pwslap01u.europe.root.pri> In-reply-to: <121202135940.ZM19771@torch.brasslantern.com> References: <121202135940.ZM19771@torch.brasslantern.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupiluLIzCtJLcpLzFFi42I5/e/4Zd30LS1BBuu+MFkcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujA2r37MVTBKtuLJhKXsD43SBLkZODgkBE4m3p1oYIWwxiQv3 1rN1MXJxCAksZZQ4+vkVM4SznEniZ/dqVpAqFgFViTObD4PZbAKGElM3zQbq5uAQEdCWaP8o BmIKC+hJHH/gAVLBK2Avsf36L3aQMKeAlcTV1hyQsJBAlkR770Q2EJtfQF/i6t9PTBAn2EvM vHKGEaJVUOLH5HssIDazgJbE5m1NrBC2vMTmNW+ZJzAKzEJSNgtJ2SwkZQsYmVcxiqaWJhcU J6XnGukVJ+YWl+al6yXn525ihITf1x2MS49ZHWIU4GBU4uEt2NkcJMSaWFZcmXuIUYKDWUmE t3VtS5AQb0piZVVqUX58UWlOavEhRiYOTqkGRubyclnpS2Y7FFbKiYZ7C3K6b/igXfTl59a9 j32vBIRFhRUUcPhw3OSdf26ZE3+NpXJfzHNt49mPzhhpREyKMC97Zam67Mr56R4Fcqs3KK2e 9C58Y5wK+xmBXW2HdcuXHej6mfT/9suSGr30rSobA2q1NwQovnh1+H5ozs3lC1T2tMuH+j3j U2Ipzkg01GIuKk4EAPf/gWYdAgAA On Sun, 02 Dec 2012 13:59:40 -0800 Bart Schaefer wrote: > 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)) I've just very verybelatedly tracked down some problems I've been seeing combining integers and floats... % print $(( 0x3000 + 0.5 )) zsh: bad math expression: operator expected at `x3000 + 0....' to this memchr(), which is overkill --- it scans the entire rest of the expression. The only difficult case, in fact, is the test for OCTALZEROES (both the option setting and checking the number), since for hexadecimal we have an explicit signal that the value is a hex integer and it certainly can't be a float if we find that. It was almost there: the problem was when we discovered it wasn't an octal we didn't continue with the normal code for parsing the number before the decimal point if octalzeroes *wasn't* set (noted by Bart in the original message). So I think this is the simplest fix. The while loop will perform one extra set of tests if OCTALZEROES *is* set, but anything to remove that is just as complicated as leaving it this way. diff --git a/Src/math.c b/Src/math.c index b21a3ad..42355f8 100644 --- a/Src/math.c +++ b/Src/math.c @@ -448,9 +448,7 @@ lexconstant(void) if (*nptr == '-') nptr++; - if (*nptr == '0' && - (memchr(nptr, '.', strlen(nptr)) == NULL)) - { + if (*nptr == '0') { nptr++; if (*nptr == 'x' || *nptr == 'X') { /* Let zstrtol parse number with base */ @@ -491,11 +489,8 @@ lexconstant(void) nptr = ptr2; } } - else - { - while (idigit(*nptr) || *nptr == '_') - nptr++; - } + while (idigit(*nptr) || *nptr == '_') + nptr++; if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') { char *ptr2; diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst index c19135c..7b005c2 100644 --- a/Test/C01arith.ztst +++ b/Test/C01arith.ztst @@ -258,3 +258,11 @@ >0.5 >3 >3. + + print $(( 0x30 + 0.5 )) + print $(( 077 + 0.5 )) + (setopt octalzeroes; print $(( 077 + 0.5 )) ) +0:Mixed float and non-decimal integer constants +>48.5 +>77.5 +>63.5 pws