Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Accuracy Of Tcl Calculations

Posted by Graham_Tasker (Graham_Tasker), 8 March 2005
Graham :

Back in December I can remenber that we discussed the accuracy of Tcl Calculations, but I cannot remenber what was said, so this question :

All Tcl data is stored as strings, so when you do a calculation using the expr command that data is first converted into a numeric type. But what 'type'? 1.234 would be converted to a float, but would it be a long float (64 bits) or a float (32 bits)? Would 123 be converted to an Integer or a Float? What about the convertion back, who many digits would be written to the string? How much accuracy is lost during this process?

This quetion relates back to the problem is representing any floating point number on a computer.

Thanks : Graham Tasker

Posted by admin (Graham Ellis), 8 March 2005
It's using double precision floats internally, but the conversion to and from strings degrades it from that a little - see the following example.

Code:
earth-wind-and-fire:~/mar05 grahamellis$ tclsh
% set fred [expr 1 / 3.]
0.333333333333
% format "%.12f" $fred
0.333333333333
% format "%.20f" $fred
0.33333333333333331483
% puts $fred
0.333333333333
% earth-wind-and-fire:~/mar05 grahamellis$


If all of the inputs to en expr are integers, integer arithmetic is performed.  So 123 will only be converted to a float if the other value in a division / multiply / etc is a float.

Graham



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho