Skip to content
Tcl Source Code Artifact [2460ea47a8]
Login

Artifact [2460ea47a8]

Artifact 2460ea47a838d6cf5ed20b4e1c5c5d70d2970860:

Ticket change [2460ea47a8] - Closed ticket [50dfde221669097e|50dfde2216]: <i>facing issue with expr</i> plus 11 other changes by dkf on 2015-03-05 10:57:36.
D 2015-03-05T10:57:36.817
J assignee kbk
J closedate 2457086.95667612
J closer dkf
J comment Found\sproblem\swith\s"expr"\swhile\sdoing\scalculations\s\r\nFor\sexample\s:\s\r\n%\sexpr\s(576.64\s-\s554.176)\s*\s1.0\s/\s0.576\r\n39.0\r\n%\sexpr\sint((576.64\s-\s554.176)\s*\s1.0\s/\s0.576)\r\n38\s\r\n\r\nHow\scome\sthe\sint\sfor\s39.0\swill\sbecome\s38?
J icomment The\sissue\sis\sthat\sthe\scalculation\sisn't\syielding\sthe\svalue\sthat\syou\sthink\sit\sis;\swhen\sI\stry\swith\sTcl\s8.5\sor\s8.6\s(both\sof\swhich\sare\s<i>much</i>\smore\scareful\sin\sthe\srendering\sof\sfloating\spoint\snumbers\sthan\s8.4\sand\sbefore\swere),\sI\sget\sthis:\r\n<pre>%\sexpr\s(576.64\s-\s554.176)\s*\s1.0\s/\s0.576\r\n38.9999999999999</pre>\r\nBinary\sfloating\spoint\snumbers\s(such\sas\sTcl\suses,\salong\swith\s<i>many</i>\sother\sprogramming\slanguages)\sare\sfundamentally\snot\scapable\sof\sdelivering\sperfectly\saccurate\scalculations\sfor\severy\svalue\syou\scan\stype\sin,\sin\sa\sway\sthat\sis\sprecisely\sanalogous\sto\show\syou\scan't\srepresent\sthe\sresult\sof\sdividing\s1\sby\s3\sin\sa\sfinite\snumber\sof\sdecimals.\sFor\smore\sinfo\ssee\s<a\shref="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html">this\sclassic\spaper</a>.\r\n<p>\r\nThe\sone\sinteresting\sthing\sabout\sTcl\sis\sthat\swe\snow\sguarantee\sto\suse\sthe\sminimum\snumber\sof\sdigits\sto\srepresent\sa\snumber\swhen\sconverting\sfrom\sthe\sfloating\spoint\sinternal\srepresentation\sto\sthe\sdecimal\sstring\sform,\ssubject\sto\sthe\sconstraint\sthat\sthe\sreverse\soperation\s(string-to-IEEE-<tt>double</tt>)\sgives\sexactly\sthe\ssame\sthing.\sThat\sis\sa\snon-trivial\sguarantee;\sit\stakes\squite\sa\slot\sof\scode\sin\sTcl's\simplementation\sto\sachieve\sit.\sIf\syou\sreally\swant\sto\suse\sa\ssmaller\snumber\sof\sdigits\sthan\swhat\sis\sproperly\snecessary,\sthe\s<tt>format</tt>\scommand\sis\sthe\sright\sapproach,\sthough\syou\sshould\sbe\saware\sthat\sthis\swill\sdo\ssome\srounding.
J login dkf
J mimetype text/html
J resolution Invalid
J severity Cosmetic
J status Closed
J subsystem 47.\sBytecode\sCompiler
J username dkf
K 50dfde221669097ea777859a00d47fb1eae03387
U dkf
Z e0ebffc18e3de1c7c921f29ba6da71bf