Artifacts Associated With Ticket 1003145
Ticket change [762a0e6e92] (rid 105526) by s_a_white on 2004-08-04 09:55:09:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Perhaps related to bug 866469? Preferred after int conversion a consistant output on all operations, preferrably giving the same results as C for a similar double to int conversion. Test: proc test { val } { set scaling 100 puts "\t$val" set out [expr { $val * $scaling }] puts "\t$out" set out [expr { int($out) }] puts "\t$out" return $out } puts "test1:" set a "999996.0" puts "\t$a" puts "\t[expr { int($a) }]" puts "test2:" set a 9999.96 puts "\t$a" set a [expr { $a * 100.0 }] puts "\t$a" puts "\t[expr { int($a) }]" puts "test3:" set a 9999.96 puts "\t$a" set a [expr { $a * 100 }] puts "\t$a" puts "\t[expr { int($a) }]" puts "test4:" puts "\t[test 9999.96]" Results: test1: 999996.0 999996 test2: 9999.96 999996.0 999995 test3: 9999.96 999996.0 999995 test4: 9999.96 999996.0 999995 999995 C result is always 999996 for the provided double value. - foundin initialized to: "obsolete: 8.4.5"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "s_a_white"
- subsystem initialized to: "None"
- title initialized to:
expr int operation giving different results for same values
- type initialized to: "Bug"
Ticket change [68ab88ff11] (rid 103110) by dkf on 2004-08-04 17:25:16:
- subsystem changed to: "47. Bytecode Compiler"
Ticket change [ec46625b77] (rid 103684) by dkf on 2004-08-04 17:25:17:
- icomment:
Logged In: YES user_id=79902 Floating point is *very* mysterious. Demystify a bit by setting tcl_precision to 17 C compilers do many aggressive optimizations often, and floating point math on Intel is actually usually done using more bits of precision than the IEEE spec calls for (and Tcl can't really take advantage of that sort of thing.)
- login: "dkf"
- mimetype: "text/plain"
- priority changed to: "2"
- username: "dkf"
- icomment:
Ticket change [261800875b] (rid 88282) by s_a_white on 2004-08-04 19:42:18:
- icomment:
Logged In: YES user_id=59929 Well as said it wasn't really the actual maths results that were the problem, just the fact that you could have two different results from the same string/operations. I hunted around a bit more and found TIP 132 (I think it was) outlining the problem in more detail. I can understand the issue now in that internally your working at a higher resolution than tcl_precision and that the result of puts is based on a rounded version using tcl_percision. I have no idea if all the suggestions recommened in that tip would fix things in a way that produces sensible output. To me (if possible) it would be quite acceptable to round results at end of maths operations to the required precision that was set by tcl_precision. That way results would be consistant with the output of puts and users can still increase tcl_precision as required for better results.
- login: "s_a_white"
- mimetype: "text/plain"
- username: "s_a_white"
- icomment:
Ticket change [bb744a8fe3] (rid 129485) by dkf on 2004-08-06 15:03:41:
- assignee changed to: "dkf"
- closedate changed to: "2004-08-06T08:03:41"
- closer changed to: "dkf"
- icomment:
Logged In: YES user_id=79902 Further comment: I don't know what C compiler you're using, but I don't get 999996 throughout for C. (See below for details.) This indicates to me that your expectations of floating point math are unrealistic and that this is not actually a bug. IOW, everything's happening just right, but you don't think the world should be arranged that way. Tough luck. ------PROGRAM------ #include <stdio.h> int main() { double d = 999996.0; printf("%f\t%d\n", d, (int)d); d = 9999.96; printf("%f\t%d\n", d, (int)d); d *= 100.0; printf("%f\t%d\n", d, (int)d); d = 9999.96; printf("%f\t%d\n", d, (int)d); d *= 100; printf("%f\t%d\n", d, (int)d); return 0; } ------OUTPUT------ 999996.000000 999996 9999.960000 9999 999996.000000 999995 9999.960000 9999 999996.000000 999995 ------MISC.INFO------ Compiled with: gcc -O3 -Wall Compiled and run on: AMD Athlon running RH9 with gcc 3.2.2 - login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Closed"
- username: "dkf"