zsh-workers
 help / color / mirror / code / Atom feed
* Those patches Re: $[ 09.5 ]  -- bad math expression
       [not found] ` <20121202210516.66e31219@pws-pc.ntlworld.com>
@ 2012-12-04 15:52   ` Bart Schaefer
  2012-12-04 16:07     ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2012-12-04 15:52 UTC (permalink / raw)
  To: zsh-workers

[>workers]

We have two patches for this.  PWS (users/17447) seems to have found
a bug with OCTAL_ZEROES that my patch (17445) won't address, though
I'm not sure what that bug is.  My C01arith.ztst patch looks for a
couple of things that Peter's doesn't -- perhaps combine tests?  In
any case there's a typo in the description part of Peter's test:

On Dec 2,  9:05pm, Peter Stephenson wrote:
}
} +  # 3/4 is a multiple of power of two so assume it's represented exactly.
} +  print ${$(( 09.75 * 4))%%.*}
} +0:leading underscores
} +>39

(Not "underscores")

Curiosity question:  Since this is just a parsing exercise, what's the
reason for the * 4 ?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Those patches Re: $[ 09.5 ]  -- bad math expression
  2012-12-04 15:52   ` Those patches Re: $[ 09.5 ] -- bad math expression Bart Schaefer
@ 2012-12-04 16:07     ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2012-12-04 16:07 UTC (permalink / raw)
  To: zsh-workers

On Tue, 04 Dec 2012 07:52:26 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> We have two patches for this.  PWS (users/17447) seems to have found
> a bug with OCTAL_ZEROES that my patch (17445) won't address, though
> I'm not sure what that bug is.

I don't believe that any more.  The code is just skipping leading zeroes
for floating point constants in an ever so slightly obscure way.
My change makes it a bit clearer but less efficient.  I don't think
there's any problem with your change.

pws


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: $[ 09.5 ]  -- bad math expression
       [not found] ` <121202135940.ZM19771@torch.brasslantern.com>
@ 2013-11-14 11:30   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2013-11-14 11:30 UTC (permalink / raw)
  To: Zsh Hackers' List

On Sun, 02 Dec 2012 13:59:40 -0800
Bart Schaefer <schaefer@brasslantern.com> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-14 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <alpine.DEB.2.00.1212022323450.27859@oreo.lan>
     [not found] ` <20121202210516.66e31219@pws-pc.ntlworld.com>
2012-12-04 15:52   ` Those patches Re: $[ 09.5 ] -- bad math expression Bart Schaefer
2012-12-04 16:07     ` Peter Stephenson
     [not found] ` <121202135940.ZM19771@torch.brasslantern.com>
2013-11-14 11:30   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).