summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 02:18:14 (GMT)
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 02:18:14 (GMT)
commit8ca1e1238e626ccb2e371bd4e1043d95aea03930 (patch)
tree321a2f2979606b1920d963775623fd77ebe380c3 /random.c
parent479b17ed12c749eb2e6716672b0c0765ad87267a (diff)
* random.c (int_pair_to_real_inclusive): Use rb_integer_pack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/random.c b/random.c
index b5c0c4c..f71b3b0 100644
--- a/random.c
+++ b/random.c
@@ -302,21 +302,11 @@ int_pair_to_real_inclusive(uint32_t a, uint32_t b)
#endif
}
else {
-#if 64 % BITSPERDIG == 0
- long len = RBIGNUM_LEN(x);
- BDIGIT *xd = BDIGITS(x);
- MEMMOVE(xd, xd + 64 / BITSPERDIG, BDIGIT, len - 64 / BITSPERDIG);
- MEMZERO(xd + len - 64 / BITSPERDIG, BDIGIT, 64 / BITSPERDIG);
- r = rb_big2dbl(x);
-#else
- x = rb_big_rshift(x, INT2FIX(64));
- if (FIXNUM_P(x)) {
- r = (double)FIX2ULONG(x);
- }
- else {
- r = rb_big2dbl(x);
- }
-#endif
+ uint32_t uary[4];
+ rb_integer_pack(x, NULL, NULL, uary, numberof(uary), sizeof(uint32_t), 0,
+ INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
+ /* r = x >> 64 */
+ r = (double)uary[0] * (0x10000 * (double)0x10000) + (double)uary[1];
}
return ldexp(r, -53);
}