From 9a8dfbb7b5ac843c7ae8dd12339911c0ea8103fb Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 18 Dec 2002 16:57:02 +0000 Subject: 18013: Handle test of (( float == 0.0)) properly --- ChangeLog | 6 ++++++ Src/builtin.c | 7 ++++--- Src/exec.c | 7 ++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15ec73d74..315ecbc72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-12-18 Peter Stephenson + + * 18013: Src/builtin.c, Src/exec.c: let and (( ... )) should + return zero status on floating point only if the value compares + equal to 0 as a floating point number. + 2002-12-11 Peter Stephenson * 17996: Src/builtin.c: Improve formatting with `print -C' by diff --git a/Src/builtin.c b/Src/builtin.c index f9f65e961..530bba8c8 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4759,13 +4759,14 @@ bin_ttyctl(char *name, char **argv, Options ops, int func) 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 * diff --git a/Src/exec.c b/Src/exec.c index 76ca437f4..978470251 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3087,7 +3087,7 @@ static int 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 @@ execarith(Estate state, int do_exec) if (isset(XTRACE)) fprintf(xtrerr, " %s", e); - val = mathevali(e); + val = matheval(e); cmdpop(); @@ -3110,7 +3110,8 @@ execarith(Estate state, int do_exec) 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 */ -- cgit 1.4.1