Skip to content
Tcl Source Code History Of Ticket 2015452
Login

History Of Ticket 2015452

Artifacts Associated With Ticket 2015452

  1. Ticket change [c27113cc10] (rid 111485) by karll on 2008-07-10 22:27:41:

    1. assignee initialized to: "dkf"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      If I divide a negative integer by an integer and there is a remainder, Tcl will round the result downward.  This has been replicated on Mac and FreeBSD.
      
      tclsh8.4
      % expr -501/500
      -2
      
      % expr -1000001/1000000
      -2
      
      Let's try a C program to see if I am crazy.
      
      $ cat foo.c
      
      main()
      {
          int i = -86401 / 86400;
          printf("%d\n", i);
      }
      
      $ cc foo.c
      $ ./a.out
      -1
      
      It works as expected.
      
      
      
    4. foundin initialized to: "obsolete: 8.4.19"
    5. is_private initialized to: "0"
    6. priority initialized to: "9 Immediate"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "karll"
    10. subsystem initialized to: "16. Commands A-H"
    11. title initialized to:
      Negative integer division is wrong if there is a remainder
      
    12. type initialized to: "Bug"
  2. Ticket change [0871dda0a4] (rid 89560) by karll on 2008-07-11 05:33:19:

    1. icomment:
      Logged In: YES 
      user_id=64603
      Originator: YES
      
      % expr -1/3
      -1
      
      % expr -1/1000000
      -1
      
      
      
      
    2. login: "karll"
    3. mimetype: "text/plain"
    4. username: "karll"
  3. Ticket change [16298620ca] (rid 124677) by msofer on 2008-07-11 05:44:29:

    1. closedate changed to: "2008-07-10T22:44:29"
    2. closer changed to: "msofer"
    3. icomment:
      Logged In: YES 
      user_id=148712
      Originator: NO
      
      The problem is with the expectation! This is the behaviour by design.
      
      From the expr man page: "Multiply, divide, remainder. None of these operators may be applied to string operands, and remainder may be applied only to integers. The remainder will always have the same sign as the divisor and an absolute value smaller than the divisor."
      
      The observed behaviour is implied by this and general identity for integers
         a = (a/b)*b + (a%b)
      
      Note that the C standard makes no such promises about the sign of the remainder, different implementations may give different results.
      
      Note also that there is no "rounding", neither up nor down: this is just the way that integer division is defined.
      
      
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Pending"
    8. username: "msofer"
  4. Ticket change [4b9ceae5fc] (rid 126741) by karll on 2008-07-11 06:01:54:

    1. closedate changed to: "2008-07-10T23:01:54"
    2. closer changed to: "karll"
    3. status changed to: "Closed"