Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 18e269a0c64c0cdc410cfb3034e3e619d493b6b7 1 parent d4560fa
Watson Watson1978 authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 random.c
8 random.c
View
@@ -74,6 +74,7 @@ rand_init(struct MT *mt, VALUE vseed)
{
VALUE seed;
long blen = 0;
+ long fixnum_seed;
int i, j, len;
unsigned int buf0[SIZEOF_LONG / SIZEOF_INT32 * 4], *buf = buf0;
@@ -81,9 +82,12 @@ rand_init(struct MT *mt, VALUE vseed)
switch (TYPE(seed)) {
case T_FIXNUM:
len = 1;
- buf[0] = (unsigned int)(FIX2ULONG(seed) & 0xffffffff);
+ fixnum_seed = FIX2LONG(seed);
+ buf[0] = (unsigned int)(fixnum_seed & 0xffffffff);
#if SIZEOF_LONG > SIZEOF_INT32
- if ((buf[1] = (unsigned int)(FIX2ULONG(seed) >> 32)) != 0) ++len;
+ if ((long)(int)fixnum_seed != fixnum_seed) {
+ if ((buf[1] = (unsigned int)(fixnum_seed >> 32)) != 0) ++len;
+ }
#endif
break;
case T_BIGNUM:
Please sign in to comment.
Something went wrong with that request. Please try again.