% set tcl_precision 17 17 % expr 1.4 1.4Note that this change doesn't affect the inherent limitations to the precision of binary floating point numbers: double(1.4) is still less than the Platonic real number 7/5. This can be proven by multiplying it by three:
% expr { 3. * 1.4 }
4.199999999999999(Interestingly enough, multiplying by five yields an exact result:)
% expr { 5. * 1.4 }
7.0All interpreters in a process share a single tcl_precision value: changing it in one interpreter will affect all other interpreters as well. However, safe interpreters are not allowed to modify the variable. (from: TclHelp)
Donald Porter's wise advice, posted to the comp.lang.tcl newsgroup, is (edited slightly): "It is best to use tcl_precision in a 'global' way. Set it early in your program's execution, then leave it alone. For situations like above where you want to control precision of single assignment, use format.If you're doing any math at all where you care about getting the right answer, you will just [set ::tcl_precision 17], and then forget anyone suggested anything else."
RS: The funny thing about tcl_precision is that it's not there in the beginning - it is just created on demand (trace?):
% info vars tcl_rcFileName tcl_version argv argv0 tcl_interactive auto_oldpath auto_path err orCode errorInfo auto_index env tcl_patchLevel argc tcl_libPath tcl_platform tcl _library % set tcl_precision 12 % info vars tcl_rcFileName tcl_version argv argv0 tcl_interactive auto_oldpath auto_path err orCode tcl_precision errorInfo auto_index env tcl_patchLevel argc tcl_libPath tc l_platform tcl_library % unset tcl_precision % set tcl_precision 12Now you see it - now you don't. tcl_precision is the only variable I know that can be read after being unset.DGP You don't know about tcl_interactive then? Common trait - they are Tcl_LinkVar variables, script level representations of C values.
LES: I don't see it written anywhere that 17 is the maximum precision allowed, so I am saying it now.
sbron -- KBK mentioned in the Tcl Chatroom that after TIP #132 a value can be displayed the same way as before by using format with a formatstring of %#.12g
