Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e6127f382e25a4705a980e75363639f1c05991e4
Ticket: 2848176fffffffffffffffffffffffffffffffff
Invalid results from "expr", v8.4.*, v8.5.*, v8.6.*
User & Date: kchansen on 2009-09-01 03:31:19
Changes

  1. assignee changed to: "dgp"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Both crc16.tcl and crc32.tcl use a variable named "signmask", that is constructed from another variable named "signbit".
    
    For 32-bit data, signbit is 0x8000000.
    
    For 32-bit CRCs, the signmask appears to be designed to mask off the high-byte, i.e. it should end up 0x00ffffff.  Signmask is computed as follows:
    
    set signmask [expr {~$signbit>>7}]
    
    Printing $signbit shows the expected value of 0x80000000:
    
    % puts $signbit
    0x80000000
    
    But if we print the bit-complement of this (which in 32-bit land we expect to be positive) we get:
    
    % expr ~$signbit
    -2147483649
    
    When we format this using "format 0x%x" we oddly get:
    
    % format 0x%x [expr ~$signbit]
    0x7fffffff
    
    Even worse, the above calculations for signmask now no longer give 0x00FFFFFF, but rather 0xFEFFFFFF, which is pretty much guaranteed to give the wrong result.
    
    It looks like the number is kind of living in both "long-land" and 32-bit-land.  In long-land the 0x80000000 gets sign-extended from 32-bit-land, and after that the bit-complement would indeed be still negative.  But the format statement seems to think the number is 32-bit-land-only....
    
    Help!
    
  4. foundin changed to: "obsolete: 8.5.7"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "kchansen"
  10. subsystem changed to: "48. Number Handling"
  11. title changed to:
    Invalid results from "expr", v8.4.*, v8.5.*, v8.6.*
    
  12. type changed to: "Bug"