zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: floating point output
@ 2002-01-09 13:55 Peter Stephenson
  2002-01-11  0:36 ` Geoff Wing
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2002-01-09 13:55 UTC (permalink / raw)
  To: Zsh hackers list

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@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: floating point output
  2002-01-09 13:55 PATCH: floating point output Peter Stephenson
@ 2002-01-11  0:36 ` Geoff Wing
  0 siblings, 0 replies; 2+ messages in thread
From: Geoff Wing @ 2002-01-11  0:36 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson <pws@csr.com> typed:
: I just noticed:
: (( A = 1.2e12 ))
: print $A
: prints `1200000000000', with no decimal point.
...
:                                                               This might
: simply be an effect of the Solaris sprintf() implementation.
...

Presumably.  Just for general interest sake, from my Zsh built the
day before this patch (on non-Solaris):

% (( A = 1.2e12 ))
% print $A
1200000000000.0000000000
% (( A = 1.0000 ))
% print $A
1.0000000000

Regards,
-- 
Geoff Wing : <gcw@pobox.com>
Rxvt Stuff : <gcw@rxvt.org>
Zsh Stuff  : <gcw@zsh.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-01-11  0:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-09 13:55 PATCH: floating point output Peter Stephenson
2002-01-11  0:36 ` Geoff Wing

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).