TIP 488: Remove tcl_precision

Login
Author:         Arjen Markus <[email protected]>
State:          Final
Type:           Project
Vote:           Done
Created:        24-Nov-2017
Post-History:
Keywords:       Tcl, string representation, floating-point
Tcl-Version:    9.0
Tcl-Branch:     tip-488

Abstract

Currently, Tcl supports a magic variable tcl_precision that is used in the implicit formatting of floating-point numbers to string representation. It was introduced a long time ago as a means to speed up such conversion, but it has lost all usefulness since the introduction of the magic value "0" in TIP 132. This TIP proposes to remove the variable altogether.

Rationale

Tcl has long relied on the value of the magic variable tcl_precision to convert floating-point number to strings that are readable by human beings. Its origin lies in the distant past, when any value was stored as a string and the more precision was required, the more costly the conversion.

Since Tcl stores variables as Tcl_Objs instead of strings and the ubiquitous use of IEEE floating-point representation, the use of this variable has become an arcane practice, as exemplified by TIP 132, which deprecates its use in favour of a fixed, but magic, value 0, to indicate that as much precision is to be used as necessary for a faithful representation of the number as a string. In the context of IEEE representation, that means 17 digits suffice.

If a user wants to limit the number of digits by which a floating-point value is represented as a human-readable string, then much better alternatives exist in the form of the [format] command. This gives much more control over the number format than tcl_precision has ever promised.

Furthermore, its existence and the description of its implicit role has been the cause for confusion of novice Tcl programmers in the past and in recent times.

Now that we are cleaning up the code base for Tcl 9, time has come to remove this relic as well.

Proposal

Compatibility considerations

The variable has had no justifiable use since Tcl 8.5. The TIP proposing its practical deprecation was created in 2003, so 14 years ago.

Code relying on its existence may produce slightly different results, but only as far as the string representation is concerned. If the numbers are converted back from string to floating-point, then of course, differences may occur as well, but these should be viewed as bugs in the original code, as a value for tcl_precision unequal to zero and smaller than 17, will not guarantee a lossless conversion to and from strings.

Reference Implementation

A branch is available.

See Also

TIP #132: Revised Floating-Point Conversions in Tcl

Copyright

This document has been placed in the public domain.