zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: return status of let with floats
@ 2002-12-18 16:52 Peter Stephenson
  2002-12-18 17:26 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2002-12-18 16:52 UTC (permalink / raw)
  To: Zsh hackers list

(( 0.3 ))

currently returns status 1 because there is an implicit cast to
integer.  As documented, it should simply test whether the result is
zero, i.e. should function identically to

(( 0.3 == 0 ))

where the implicit cast is of the 0 to 0.0.  Certainly this seems to me
more consistent and useful.  I don't have a ksh which handles floating
point to try out, unfortunately.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.92
diff -u -r1.92 builtin.c
--- Src/builtin.c	11 Dec 2002 16:03:21 -0000	1.92
+++ Src/builtin.c	18 Dec 2002 16:48:12 -0000
@@ -4759,13 +4759,14 @@
 int
 bin_let(char *name, char **argv, Options ops, int func)
 {
-    zlong val = 0;
+    mnumber val = zero_mnumber;
 
     while (*argv)
-	val = mathevali(*argv++);
+	val = matheval(*argv++);
     /* Errors in math evaluation in let are non-fatal. */
     errflag = 0;
-    return !val;
+    /* should test for fabs(val.u.d) < epsilon? */
+    return (val.type == MN_INTEGER) ? val.u.l == 0 : val.u.d == 0.0;
 }
 
 /* umask command.  umask may be specified as octal digits, or in the  *
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.47
diff -u -r1.47 exec.c
--- Src/exec.c	4 Dec 2002 13:57:51 -0000	1.47
+++ Src/exec.c	18 Dec 2002 16:48:12 -0000
@@ -3087,7 +3087,7 @@
 execarith(Estate state, int do_exec)
 {
     char *e;
-    zlong val = 0;
+    mnumber val = zero_mnumber;
     int htok = 0;
 
     if (isset(XTRACE)) {
@@ -3101,7 +3101,7 @@
     if (isset(XTRACE))
 	fprintf(xtrerr, " %s", e);
 
-    val = mathevali(e);
+    val = matheval(e);
 
     cmdpop();
 
@@ -3110,7 +3110,8 @@
 	fflush(xtrerr);
     }
     errflag = 0;
-    return !val;
+    /* should test for fabs(val.u.d) < epsilon? */
+    return (val.type == MN_INTEGER) ? val.u.l == 0 : val.u.d == 0.0;
 }
 
 /* perform time ... command */

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: PATCH: return status of let with floats
  2002-12-18 16:52 PATCH: return status of let with floats Peter Stephenson
@ 2002-12-18 17:26 ` Oliver Kiddle
  2002-12-18 18:01   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2002-12-18 17:26 UTC (permalink / raw)
  To: zsh-workers

On 18 Dec, Peter wrote:
 
> more consistent and useful.  I don't have a ksh which handles floating
> point to try out, unfortunately.

ksh93> (( 0.3 )) && echo yup
yup

So it looks like your change is consistent with it.

All of bash, pdksh and ksh 88/93 output 0 for `echo $(( ))' by the way
while zsh gives a bad math expression error so that should perhaps also
be changed.

Oliver

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


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

* Re: PATCH: return status of let with floats
  2002-12-18 17:26 ` Oliver Kiddle
@ 2002-12-18 18:01   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2002-12-18 18:01 UTC (permalink / raw)
  To: zsh-workers

Oliver Kiddle wrote:
> All of bash, pdksh and ksh 88/93 output 0 for `echo $(( ))' by the way
> while zsh gives a bad math expression error so that should perhaps also
> be changed.

This handles that particular case, though I don't know if it's supposed
to be something more general.

Index: Src/math.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/math.c,v
retrieving revision 1.16
diff -u -r1.16 math.c
--- Src/math.c	30 Oct 2002 19:29:42 -0000	1.16
+++ Src/math.c	18 Dec 2002 17:58:44 -0000
@@ -961,7 +961,7 @@
     stack[0].val.u.l = 0;
     mathparse(prek);
     *ep = ptr;
-    DPUTS(!errflag && sp,
+    DPUTS(!errflag && sp > 0,
 	  "BUG: math: wallabies roaming too freely in outback");
 
     if (errflag) {
@@ -1084,6 +1084,9 @@
     if (errflag)
 	return;
     mtok = zzlex();
+    /* Handle empty input */
+    if (pc == TOPPREC && mtok == EOI)
+	return;
     checkunary(mtok, optr);
     while (prec[mtok] <= pc) {
 	if (errflag)

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

end of thread, other threads:[~2002-12-18 18:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-18 16:52 PATCH: return status of let with floats Peter Stephenson
2002-12-18 17:26 ` Oliver Kiddle
2002-12-18 18:01   ` 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).