Artifacts Associated With Ticket 576512ffffffffffffffffffffffffffffffffff
Ticket change [2a56a18201] (rid 118544) by nobody on 2002-07-02 18:20:03:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Using 8.2.3 (SGI), 8.3.1, or 8.3.3, (both linux) the following behavior is observed: % set x [expr 1.2*3.0] 3.6 % if {3.6 > $x} {puts "3.6 is greater than $x!"} 3.6 is greater than 3.6! % puts [expr 3.6 > $x] 0 So, apparently the expr procedure evaluates differently than the parsing of the if conditional. I would rather not make all of my if statements like: if {[expr 3.6 > $x] == 1} {...} - foundin initialized to: "None"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "None"
- title initialized to: "Math problem."
- type initialized to: "Bug"
Ticket change [47bac72330] (rid 99753) by msofer on 2002-07-03 01:56:59:
- closedate changed to: "2002-07-02T18:56:59"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 This is because the internal representation of (1.2*3.0) *is* larger than the internal representation of (3.6) - floats are weird :( Now, when you do puts [expr 3.6 > $x] expr will do double substitution - essentially, it builds the string "3.6 > $x" with '$x' replaced by the string representation of its value, then parses this string and finally evaluates the expression.The roundtrip via the string rep of '$x' causes the equality due to rounding in the float-to-string conversion. If you do instead puts [expr {3.6 > $x}] preventing the conversion to string, you obtain 1. So: it is consistent, the problem that they aren't equal is intrinsic to the binary representation of floats. This is inherited from C. See http://wiki.tcl.tk/879 for more troublesome examples with real numbers. - login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Pending"
- username: "msofer"
Ticket change [c44d61bf60] (rid 111825) by msofer on 2002-07-03 01:58:54:
- assignee changed to: "msofer"
- status changed to: "Open"
Ticket change [ccf979802e] (rid 95800) by msofer on 2002-07-03 02:00:40:
- closedate changed to: "2002-07-02T19:00:40"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 Oops: first I forget to assign to myself, then I inadvertedly change the status ...
- login: "msofer"
- mimetype: "text/plain"
- status changed to: "Pending"
- username: "msofer"
Ticket change [e65fd3af66] (rid 104282) by dgp on 2002-07-03 02:10:33:
- icomment:
Logged In: YES user_id=80530 "So, apparently the expr procedure evaluates differently than the parsing of the if conditional" No, you will find that [expr {3.6 > $x}] always gives the same result as if {3.6 > $x} {...} You did not enclose the expression in braces, so two rounds of substituion occurred, including a translation from double -> string -> double. Such translations often lose precision and change the precise floating point value. Seeking arbitrarily precise answers involving floating point values is a mistake in the first place. - login: "dgp"
- mimetype: "text/plain"
- status changed to: "Open"
- username: "dgp"
- icomment:
Ticket change [e1b71ef9b0] (rid 87503) by dkf on 2002-07-06 05:36:55:
- closedate changed to: "2002-07-05T22:36:55"
- closer changed to: "dkf"
- status changed to: "Closed"