From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7447 invoked from network); 18 Dec 2002 16:53:24 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 18 Dec 2002 16:53:24 -0000 Received: (qmail 6482 invoked by alias); 18 Dec 2002 16:53:18 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18013 Received: (qmail 6474 invoked from network); 18 Dec 2002 16:53:18 -0000 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 Message-ID: <9124.1040230364@csr.com> From: Peter Stephenson (( 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 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. **********************************************************************