Artifacts Associated With Ticket 410043ffffffffffffffffffffffffffffffffff
Ticket change [1abf1ca0e8] (rid 123035) by nobody on 2001-03-20 16:17:01:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The following script produces strange output. Script: #----------------------------------------------- set vmin 1.3 set vmax 1.7 set idx 4 set incr 0.1 set newval [expr {$vmin+int($idx)*$incr}] if { $newval > $vmax } { puts "Bare 'if' says $newval > $vmax" } else { puts "Bare 'if' says $newval <= $vmax" } if { [expr $newval > $vmax] } { puts "'if' with expr says $newval > $vmax" } else { puts "'if' with expr says $newval <= $vmax" } #----------------------------------------------- Output: Bare 'if' says 1.7 > 1.7 'if' with expr says 1.7 <= 1.7 As you see, the "if" command returns a different answer depending on whether or not you use expr. - foundin initialized to: "obsolete: 8.3"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "45. Parsing and Eval"
- title initialized to: ""if" does not evaluate same as "expr""
- type initialized to: "Bug"
Ticket change [e239a82c84] (rid 87586) by nobody on 2001-03-20 23:23:36:
- icomment:
Logged In: NO The problem seems to be that the arguments to [expr] aren't braced. I added: if { [expr {$newval > $vmax}] } { puts "'if' with braced expr says $newval > $vmax" } else { puts "'if' with braced expr says $newval <= $vmax" } and it agreed with the raw [if]. I imagine this has to do with shimmering but that's a guess. You ought to brace [expr] arguments for performance anyway so this doesn't seem like a real issue. -- Chris Nelson ([email protected]), who can't manage to log into SorceForge reliably - login: "nobody"
- mimetype: "text/plain"
- username: "nobody"
- icomment:
Ticket change [2c97a15461] (rid 118929) by dkf on 2001-03-20 23:43:47:
- closedate changed to: "2001-03-20T16:43:47"
- closer changed to: "dkf"
- icomment:
Logged In: YES user_id=79902 This problem (a known feature of Tcl that is unlikely to ever be altered for a host of deep reasons) stems from the fact that 0.1 is not a precisely representable floating point number and that arguments to [expr] are [concat]enated before evaluation. Rerun the script with tcl_precision set to 17, or with the expression to pass to [expr] in {braces}, and you'll get agreement between the "bare if" and the "if with expr". If this matters very much, use fixed-point arithmetic instead. - login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
- title changed to: ""if" does not evaluate same as "expr""
- username: "dkf"