Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 16298620ca186b7cd6e1c8397c9d56354307ff10
Ticket: 2015452fffffffffffffffffffffffffffffffff
Negative integer division is wrong if there is a remainder
User & Date: msofer on 2008-07-11 05:44:29
Changes

  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"