Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: floating point output



I just noticed:

(( A = 1.2e12 ))
print $A

prints `1200000000000', with no decimal point.  Hence if A is a scalar the
number is treated in future as an integer.  This causes problems for
example if you try to square it: try entering `1.2e12' then `$1 ** 2' in
zcalc.  The math code correctly returns a floating point number, but
convfloat doesn't check there is a `.' or `e' in the result.  This might
simply be an effect of the Solaris sprintf() implementation.  The same
occurs with e.g. 1.0000, although that's usually less of a problem.

This is the simplest patch I can think of.  I haven't added any extra
digits because the number of digits has already been worked out, just the
`.'.  I don't think this should cause problems.

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.58
diff -u -r1.58 params.c
--- Src/params.c	2001/12/18 14:51:31	1.58
+++ Src/params.c	2002/01/09 13:45:09
@@ -3357,6 +3357,8 @@
     } else {
 	VARARR(char, buf, 512 + digits);
 	sprintf(buf, fmt, digits, dval);
+	if (!strchr(buf, 'e') && !strchr(buf, '.'))
+	    strcat(buf, ".");
 	return dupstring(buf);
     }
 }

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


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