Skip to content
Tcl Source Code History Of Ticket 1003145
Login

History Of Ticket 1003145

Artifacts Associated With Ticket 1003145

  1. Ticket change [762a0e6e92] (rid 105526) by s_a_white on 2004-08-04 09:55:09:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. 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.
      
      
    4. foundin initialized to: "obsolete: 8.4.5"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "s_a_white"
    9. subsystem initialized to: "None"
    10. title initialized to:
      expr int operation giving different results for same values
      
    11. type initialized to: "Bug"
  2. Ticket change [68ab88ff11] (rid 103110) by dkf on 2004-08-04 17:25:16:

    1. subsystem changed to: "47. Bytecode Compiler"
  3. Ticket change [ec46625b77] (rid 103684) by dkf on 2004-08-04 17:25:17:

    1. 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.)
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. priority changed to: "2"
    5. username: "dkf"
  4. Ticket change [261800875b] (rid 88282) by s_a_white on 2004-08-04 19:42:18:

    1. 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.
      
      
      
    2. login: "s_a_white"
    3. mimetype: "text/plain"
    4. username: "s_a_white"
  5. Ticket change [bb744a8fe3] (rid 129485) by dkf on 2004-08-06 15:03:41:

    1. assignee changed to: "dkf"
    2. closedate changed to: "2004-08-06T08:03:41"
    3. closer changed to: "dkf"
    4. 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
      
      
    5. login: "dkf"
    6. mimetype: "text/plain"
    7. resolution changed to: "Invalid"
    8. status changed to: "Closed"
    9. username: "dkf"