Skip to content
Tcl Source Code History Of Ticket 1340260
Login

History Of Ticket 1340260

Artifacts Associated With Ticket 1340260

  1. Ticket change [b996e1884f] (rid 129171) by mdejong on 2005-10-28 04:22:54:

    1. assignee initialized to: "kennykb"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      I was just reviewing the round() implementation in Tcl 8.4
      vs Tcl 8.5. The round() implementation seems to be
      more complex than it needs to be. The attached patch
      simplifies the function so that it works more like the
      8.4 version. I also added tests cases around the min int
      and max int cases. As far and I can tell, the results of
      no tests are changed by this patch. Kevin, could you
      review this patch before I apply it?
      
    4. foundin initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "mdejong"
    9. subsystem initialized to: "16. Commands A-H"
    10. title initialized to: "Simplify round() implementation in expr cmd"
    11. type initialized to: "Patch"
  2. Add attachment "round.patch" [9c5fe292e9] (rid 96139) by mdejong on 2005-10-28 11:22:55.

  3. Ticket change [0c5dab6f4b] (rid 114165) by mdejong on 2005-10-28 11:22:56:

    1. icomment:
      
      
      File Added - 154087: round.patch
      
      
      
    2. login: "mdejong"
    3. mimetype: "text/plain"
    4. username: "mdejong"
  4. Ticket change [8b26b6d268] (rid 127511) by dkf on 2005-10-28 21:24:49:

    1. subsystem changed to: "45. Parsing and Eval"
  5. Ticket change [12ad85d0ae] (rid 124080) by kennykb on 2005-10-31 22:28:37:

    1. assignee changed to: "dgp"
    2. icomment:
      Logged In: YES 
      user_id=99768
      
      Don, I don't see anything obvious wrong with Mo's approach,
      but I haven't had time to really go over things with a
      fine-toothed
      comb.  It looks as if he has the corner cases accounted for.
      Could you give it a second look?
      
      
    3. login: "kennykb"
    4. mimetype: "text/plain"
    5. username: "kennykb"
  6. Ticket change [e8023d1b8b] (rid 104575) by dgp on 2005-11-01 21:55:14:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      The problem is with systems with
      64-bit longs.  Since IEEE doubles
      have only 53 bits of precision, the
      calculation
      
          (double) LONG_MAX - 1.0
      
      for example, can't be performed.
      That is, the subtraction is lost
      below the precision threshold.
      
      Doing the operations as longs
      doesn't suffer this problem.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  7. Ticket change [a87927d686] (rid 98998) by dgp on 2005-11-01 22:18:27:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      Here's a test case:
      
      test expr-46.13 {round() handling of long/bignum boundary} {
          expr {round(double(0x7fffffffffffffff))}
      } 9223372036854775808
      
      With the contributed patch, on L64 systems:
      
      ==== expr-46.13 round() handling of long/bignum boundary FAILED
      ==== Contents of test case:
      
          expr {round(double(0x7fffffffffffffff))}
      
      ---- Result was:
      -9223372036854775808
      ---- Result should have been (exact matching):
      9223372036854775808
      ==== expr-46.13 FAILED
      
      On the HEAD, the test passes.
      
      Committing that to the test suite...
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. resolution changed to: "Rejected"
    5. status changed to: "Closed"
    6. username: "dgp"
  8. Ticket change [532aa8d49e] (rid 126435) by dgp on 2005-11-01 22:18:28:

    1. closedate changed to: "2005-11-01T15:18:28"
    2. closer changed to: "dgp"
  9. Ticket change [e7a453be41] (rid 104502) by mdejong on 2005-11-02 01:55:18:

    1. icomment:
      Logged In: YES 
      user_id=90858
      
      Here is another test case that I find odd.
      
      % expr {wide(0x7fffffffffffffff)}
      9223372036854775807
      
      % expr {wide(double(0x7fffffffffffffff))}
      -9223372036854775808
      
      In the round() example you have below, should the result
      actually be 9223372036854775807?
      
      
    2. login: "mdejong"
    3. mimetype: "text/plain"
    4. username: "mdejong"
  10. Ticket change [d9d2e10898] (rid 107675) by dgp on 2005-11-02 02:10:15:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      expr {double(.)} converts to a
      double-precision floating point
      value, and suffers the loss of
      precision compared with a
      64-bit integer that implies.
      
      In these examples, the nearest
      double value to 0x7fffffffffffffff
      is 1.0 * 2**63, or 9223372036854775808.0
      
      Convert that back to integer using
      entier(.) to get 9223372036854775808
      
      Convert to integer and truncate to 
      wide integer range using wide(.), and
      get the results you report.
      
      Pehaps "odd" at first glance, but
      I think correct results.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  11. Ticket change [5088f15e81] (rid 125992) by kennykb on 2005-11-02 02:13:36:

    1. icomment:
      Logged In: YES 
      user_id=99768
      
      Don is correct - because of the double rounding step.
      
      Converting a wide to a double has to round to 53 significant
      bits, so converting 0x7fffffffffffffff rounds up:
      
      % expr 0x7fffffffffffffff
      9223372036854775807
      % expr entier(double(0x7fffffffffffffff))
      9223372036854775808
      
      Rounding the double then yields an integer that overflows
      when reconverted to 64-bits, so winds up being negative
      rather than positive.
      
      
    2. login: "kennykb"
    3. mimetype: "text/plain"
    4. username: "kennykb"