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

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).