about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-11-26 03:28:15 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-11-26 03:28:15 +0000
commite796b8b4f05c0ec529e4362688daa384b92f0228 (patch)
tree824a078a5e9cb88ba77d1f91241105781146b507 /Src
parent18f73fc65cd734620bbd01389fcd7b670b1db3a7 (diff)
downloadzsh-e796b8b4f05c0ec529e4362688daa384b92f0228.tar.gz
zsh-e796b8b4f05c0ec529e4362688daa384b92f0228.tar.xz
zsh-e796b8b4f05c0ec529e4362688daa384b92f0228.zip
Merge of 24068: attempt to make `printf "%g\n" -0 output "-0".
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 24af7c6d3..d5b036b26 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3849,9 +3849,25 @@ bin_print(char *name, char **args, Options ops, int func)
 			    break;
 		    case 2:
 			if (curarg) {
-			    mnumval = matheval(curarg);
-			    doubleval = (mnumval.type & MN_FLOAT) ?
-			    	mnumval.u.d : (double)mnumval.u.l;
+			    char *eptr;
+			    /*
+			     * First attempt to parse as a floating
+			     * point constant.  If we go through
+			     * a math evaluation, we can lose
+			     * mostly unimportant information
+			     * that people in standards organizations
+			     * worry about.
+			     */
+			    doubleval = strtod(curarg, &eptr);
+			    /*
+			     * If it didn't parse as a constant,
+			     * parse it as an expression.
+			     */
+			    if (*eptr != '\0') {
+				mnumval = matheval(curarg);
+				doubleval = (mnumval.type & MN_FLOAT) ?
+				    mnumval.u.d : (double)mnumval.u.l;
+			    }
 			} else doubleval = 0;
 			if (errflag) {
 			    doubleval = 0;