Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: return status of let with floats
- X-seq: zsh-workers 18013
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: return status of let with floats
- Date: Wed, 18 Dec 2002 16:52:44 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
(( 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@xxxxxxx> 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.
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author