diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-07 22:22:36 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-07 22:22:36 +0000 |
commit | f571492922083d0a02d2dc5ee5125af52935d5cd (patch) | |
tree | 57356bc5b6b0883e8b98c6331b0a7b4e409061d0 /random.c | |
parent | 0f58f9dbe7bf81595b78bcee9cab49a4a546ba80 (diff) |
* random.c (rand_init): ignore higher bits if all they are same as
the lower sign bit. [ruby-core:29292](2)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r-- | random.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -367,6 +367,7 @@ rand_init(struct MT *mt, VALUE vseed) { volatile VALUE seed; long blen = 0; + long fixnum_seed; int i, j, len; unsigned int buf0[SIZEOF_LONG / SIZEOF_INT32 * 4], *buf = buf0; @@ -374,9 +375,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: |