mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
479b17ed12
commit
8ca1e1238e
2 changed files with 9 additions and 15 deletions
|
@ -1,3 +1,7 @@
|
|||
Sat Jun 8 11:17:39 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* random.c (int_pair_to_real_inclusive): Use rb_integer_pack.
|
||||
|
||||
Sat Jun 8 09:49:42 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* random.c (int_pair_to_real_inclusive): Use rb_integer_unpack.
|
||||
|
|
20
random.c
20
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue