zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: return status of let with floats
Date: Wed, 18 Dec 2002 16:52:44 +0000	[thread overview]
Message-ID: <9124.1040230364@csr.com> (raw)

(( 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.
**********************************************************************


             reply	other threads:[~2002-12-18 16:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-18 16:52 Peter Stephenson [this message]
2002-12-18 17:26 ` Oliver Kiddle
2002-12-18 18:01   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9124.1040230364@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).