Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0b30c6321c166c73772afa72b6d34d0d543e9f64
Ticket: 221072ffffffffffffffffffffffffffffffffff
rand() > 1 on 64-bit platform
User & Date: dgp on 2000-11-02 13:23:41
Changes

  1. icomment:
    Here's a patch that fixes the bug (test suite patched too):
    
    *** generic/tclExecute.c.orig   Wed Nov  1 23:27:14 2000
    --- generic/tclExecute.c        Thu Nov  2 00:29:05 2000
    ***************
    *** 4094,4107 ****
          }
      
          /*
    !      * On 64-bit architectures we need to mask off the upper bits to
    !      * ensure we only have a 32-bit range.  The constant has the
    !      * bizarre form below in order to make sure that it doesn't
    !      * get sign-extended (the rules for sign extension are very
    !      * concat, particularly on 64-bit machines).
           */
      
    !     iPtr->randSeed &= ((((unsigned long) 0xfffffff) << 4) | 0xf);
          dResult = iPtr->randSeed * (1.0/RAND_IM);
      
          /*
    --- 4094,4108 ----
          }
      
          /*
    !      * We're about to derive the double dResult by dividing the long
    !      * iPtr->randSeed by RAND_IM.  We want dResult to be in the range
    !      * 0 <= dResult < 1.  In case, you didn't notice, RAND_IM = 2^31 - 1,
    !      * or, in hex, 0x7fffffff.  So, we need to be sure that iPtr->randSeed
    !      * is in the range 0x0 <= iPtr < 0x7fffffff.  We can accomplish this
    !      * by masking away all but the 31 least significant bits.
           */
      
    !     iPtr->randSeed &= (unsigned long) 0x7fffffff;
          dResult = iPtr->randSeed * (1.0/RAND_IM);
      
          /*
    *** tests/expr-old.test.orig    Thu Nov  2 00:15:22 2000
    --- tests/expr-old.test Thu Nov  2 00:04:58 2000
    ***************
    *** 825,830 ****
    --- 825,833 ----
      test expr-old-32.51 {math functions in expressions} {
          list [catch {expr {srand([lindex "6ty" 0])}} msg] $msg
      } {1 {argument to math function didn't have numeric value}}
    + test expr-old-32.52 {math functions in expressions} {
    +     expr srand(1<<37) < 1
    + } {1}
      
      test expr-old-33.1 {conversions and fancy args to math functions} {
          expr hypot ( 3 , 4 )
    
    This patch replaces a tricky bit of code especially written to support 64-bit platforms (but did not work on mine) with a simpler approach that works on my 64-bit platform.  The patch appears to me to be portable, but I suppose some testing on other 64-bit platforms would be a good idea.
    
    Now the process questions:
    
    Does the patch belong here, or should it go in the Patch Manager?  If it belongs in the Patch Manager, how should I cross-reference the bug it fixes?
    
    Who will check in this patch?  I'm not (yet) a maintainer of anything, and besides, as far as I can tell, I no longer have commit access to any CVS repository containing Tcl.
    
    Why did I have to make myself a Bug Tracker Tech & Admin
    just to be able to post this followup comment?  Shouldn't we set up the Bug Tracker to accept followup comments (that might contain bug fix submissions) from anybody?  Is that not possible?
    
    
  2. login: "dgp"
  3. mimetype: "text/plain"
  4. username: "dgp"