Skip to content
This repository
Browse code

ignore higher bits if all they are same as the lower sign bit

  • Loading branch information...
commit 18e269a0c64c0cdc410cfb3034e3e619d493b6b7 1 parent d4560fa
Watson authored January 10, 2012

Showing 1 changed file with 6 additions and 2 deletions. Show diff stats Hide diff stats

  1. 8  random.c
8  random.c
@@ -74,6 +74,7 @@ rand_init(struct MT *mt, VALUE vseed)
74 74
 {
75 75
     VALUE seed;
76 76
     long blen = 0;
  77
+    long fixnum_seed;
77 78
     int i, j, len;
78 79
     unsigned int buf0[SIZEOF_LONG / SIZEOF_INT32 * 4], *buf = buf0;
79 80
 
@@ -81,9 +82,12 @@ rand_init(struct MT *mt, VALUE vseed)
81 82
     switch (TYPE(seed)) {
82 83
       case T_FIXNUM:
83 84
 	len = 1;
84  
-	buf[0] = (unsigned int)(FIX2ULONG(seed) & 0xffffffff);
  85
+	fixnum_seed = FIX2LONG(seed);
  86
+	buf[0] = (unsigned int)(fixnum_seed & 0xffffffff);
85 87
 #if SIZEOF_LONG > SIZEOF_INT32
86  
-	if ((buf[1] = (unsigned int)(FIX2ULONG(seed) >> 32)) != 0) ++len;
  88
+	if ((long)(int)fixnum_seed != fixnum_seed) {
  89
+	    if ((buf[1] = (unsigned int)(fixnum_seed >> 32)) != 0) ++len;
  90
+	}
87 91
 #endif
88 92
 	break;
89 93
       case T_BIGNUM:

0 notes on commit 18e269a

Please sign in to comment.
Something went wrong with that request. Please try again.