Artifacts Associated With Ticket 218443
Ticket change [33841e7bf8] (rid 106606) by nobody on 2000-10-26 00:57:39:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
OriginalBugID: 6295 Bug Version: 8.3.2 SubmitDate: '2000-09-21' LastModified: '2000-10-18' Severity: MED Status: Closed Submitter: techsupp ChangedBy: ericm OS: All Windows OSVersion: Windows NT 4.0 Machine: Dell Dimension P200 FixedDate: '2000-10-25' ClosedDate: '2000-10-18' Name: Jon Hilbert ReproducibleScript: for {set i 0} {$i < 10} {incr i} {set a($i) "0.10"} set total 0 for {set i 0} {$i < 10} {incr i} {set total [expr {$total + $a($i)}]} if {$total != 1.0} {puts "what? why doesn't $total == 1.0 ?"} if {[expr $total] == 1.0} {puts "but \[expr $total] == 1.0 ?"} info patchlevel ObservedBehavior: as the script shows, the results of "if {$total != 1.0}" are not the same as "if {[expr $total] != 1.0}". I think they should be. Floating-point comparisons are notoriously unreliable. Likely what you are hitting here is an artifact of the limitations of floating-point arithmetic inherent in all computer platforms. If you must perform floating-point equality comparisons, you are better off with something like: set tolerance 0.001 if { 1.0 - $tolerance <= $total && $total <= 1.0 + $tolerance } { ... } That is, allow for a "slush factor" in the comparison by testing that the value is "tolerably close" to the expected value. Eric Melski The Other Tcl Guy ericm at ajubasolutions.com Ajuba Solutions -- 10/18/2000 ericm - foundin initialized to: "obsolete: 8.3.2"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "69. Other"
- title initialized to:
an if expression comparing a computed floating point value w
- type initialized to: "Bug"
Ticket change [400b04fe04] (rid 121559) by welch on 2000-10-26 08:22:16:
- closedate changed to: "2000-10-26T01:22:16"
- closer changed to: "welch"
- priority changed to: "2"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [9bb8923d96] (rid 111174) by dgp on 2001-04-20 02:41:06:
- closedate changed to: "2001-04-19T19:41:06"
- closer changed to: "dgp"
- resolution changed to: "Invalid"
- subsystem changed to: "16. Commands A-H"