summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2011-01-15 18:10:18 (GMT)
committerKevin B Kenny <kennykb@acm.org>2011-01-15 18:10:18 (GMT)
commit3aded4ee3f9fa66143b3b8b4be6b021243515cf1 (patch)
tree51b622116570a04f374cceb905e6453578b77cae /doc
parent825e2402afb20392182bfdb0cc585bf5f2c5f89d (diff)
downloadtcl-3aded4ee3f9fa66143b3b8b4be6b021243515cf1.zip
tcl-3aded4ee3f9fa66143b3b8b4be6b021243515cf1.tar.gz
tcl-3aded4ee3f9fa66143b3b8b4be6b021243515cf1.tar.bz2
* doc/tclvars.n:
* generic/tclStrToD.c: * generic/tclUtil.c (Tcl_PrintDouble): * tests/util.test (util-16.*): Restored full Tcl 8.4 compatibility for the formatting of floating point numbers when $::tcl_precision is not zero. Added compatibility tests to make sure that excess trailing zeroes are suppressed for all eight major code paths. [Bug 3157475]
Diffstat (limited to 'doc')
-rw-r--r--doc/tclvars.n33
1 files changed, 26 insertions, 7 deletions
diff --git a/doc/tclvars.n b/doc/tclvars.n
index 32d4b08..45498c8 100644
--- a/doc/tclvars.n
+++ b/doc/tclvars.n
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: tclvars.n,v 1.43 2010/11/15 21:34:54 andreas_kupries Exp $
+'\" RCS: @(#) $Id: tclvars.n,v 1.44 2011/01/15 18:10:19 kennykb Exp $
'\"
.so man.macros
.TH tclvars n 8.0 Tcl "Tcl Built-In Commands"
@@ -365,22 +365,41 @@ binary number.
.RE
.PP
.RS
-17 digits is
+If \Btcl_precision\fB is not zero, then when Tcl converts a floating
+point number, it creates a decimal representation of at most
+\fBtcl_precision\fR significant digits; the result may be shorter if
+the shorter result represents the original number exactly. If no
+result of at most \fBtcl_precision\fR digits is an exact representation
+of the original number, the one that is closest to the original
+number is chosen.
+If the original number lies precisely between two equally accurate
+decimal representations, then the one with an even value for the least
+significant digit is chosen; for instance, if tcl_precision is 3, then
+0.3125 will convert to 0.312, not 0.313, while 0.6875 will convert to
+0.688, not 0.687. Any string of trailing zeroes that remains is trimmed.
+.RE
+.PP
+.RS
+a \fBtcl_precision\fR value of 17 digits is
.QW perfect
for IEEE floating-point in that it allows
double-precision values to be converted to strings and back to
-binary with no loss of information. However, using 17 digits prevents
-any rounding, which produces longer, less intuitive results. For example,
-\fBexpr {1.4}\fR returns 1.3999999999999999 with \fBtcl_precision\fR
-set to 17, vs. 1.4 if \fBtcl_precision\fR is 12.
+binary with no loss of information. For this reason, you will often
+see it as a value in legacy code that must run on Tcl versions before
+8.5. It is no longer recommended; as noted above, a zero value is the
+preferred method.
.RE
.PP
.RS
All interpreters in a thread share a single \fBtcl_precision\fR value:
changing it in one interpreter will affect all other interpreters as
-well. However, safe interpreters are not allowed to modify the
+well. Safe interpreters are not allowed to modify the
variable.
.RE
+.PP
+.RS
+Valid values for \Btcl_precision\fR range from 0 to 17.
+.RE
.TP
\fBtcl_rcFileName\fR
.