.
D 2000-10-26T00:57:39
J assignee nobody
J cmimetype text/plain
J comment OriginalBugID:\s6295\sBug\nVersion:\s8.3.2\nSubmitDate:\s'2000-09-21'\nLastModified:\s'2000-10-18'\nSeverity:\sMED\nStatus:\sClosed\nSubmitter:\stechsupp\nChangedBy:\sericm\nOS:\sAll\sWindows\nOSVersion:\sWindows\sNT\s4.0\nMachine:\sDell\sDimension\sP200\nFixedDate:\s'2000-10-25'\nClosedDate:\s'2000-10-18'\n\n\nName:\nJon\sHilbert\n\nReproducibleScript:\nfor\s{set\si\s0}\s{$i\s<\s10}\s{incr\si}\s{set\sa($i)\s"0.10"}\nset\stotal\s0\nfor\s{set\si\s0}\s{$i\s<\s10}\s{incr\si}\s{set\stotal\s[expr\s{$total\s+\s$a($i)}]}\nif\s{$total\s!=\s1.0}\s{puts\s"what?\swhy\sdoesn't\s$total\s==\s1.0\s?"}\nif\s{[expr\s$total]\s==\s1.0}\s{puts\s"but\s\\[expr\s$total]\s==\s1.0\s?"}\ninfo\spatchlevel\n\nObservedBehavior:\nas\sthe\sscript\sshows,\sthe\sresults\sof\s"if\s{$total\s!=\s1.0}"\sare\snot\sthe\ssame\sas\s"if\s{[expr\s$total]\s!=\s1.0}".\sI\sthink\sthey\sshould\sbe.\n\n\n\nFloating-point\scomparisons\sare\snotoriously\sunreliable.\s\sLikely\swhat\syou\sare\shitting\shere\sis\san\sartifact\sof\sthe\slimitations\sof\sfloating-point\sarithmetic\sinherent\sin\sall\scomputer\splatforms.\n\nIf\syou\smust\sperform\sfloating-point\sequality\scomparisons,\syou\sare\sbetter\soff\swith\ssomething\slike:\n\nset\stolerance\s0.001\nif\s{\s1.0\s-\s$tolerance\s<=\s$total\s&&\s$total\s<=\s1.0\s+\s$tolerance\s}\s{\n...\n}\n\nThat\sis,\sallow\sfor\sa\s"slush\sfactor"\sin\sthe\scomparison\sby\stesting\sthat\sthe\svalue\sis\s"tolerably\sclose"\sto\sthe\sexpected\svalue.\n\n\s\s\sEric\sMelski\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sThe\sOther\sTcl\sGuy\n\s\s\sericm\sat\sajubasolutions.com\s\s\s\s\s\s\s\s\s\s\s\sAjuba\sSolutions\n\n--\s10/18/2000\sericm\n\n
J foundin obsolete:\s8.3.2
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 69.\sOther
J title an\sif\sexpression\scomparing\sa\scomputed\sfloating\spoint\svalue\sw
J type Bug
K 218443ffffffffffffffffffffffffffffffffff
U nobody
Z 6e020c2e3df803b5daa8645b05fafab8