ruby-changes:29109
From: akr <ko1@a...>
Date: Sat, 8 Jun 2013 11:18:27 +0900 (JST)
Subject: [ruby-changes:29109] akr:r41161 (trunk): * random.c (int_pair_to_real_inclusive): Use rb_integer_pack.
akr 2013-06-08 11:18:14 +0900 (Sat, 08 Jun 2013) New Revision: 41161 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41161 Log: * random.c (int_pair_to_real_inclusive): Use rb_integer_pack. Modified files: trunk/ChangeLog trunk/random.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41160) +++ ChangeLog (revision 41161) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jun 8 11:17:39 2013 Tanaka Akira <akr@f...> + + * random.c (int_pair_to_real_inclusive): Use rb_integer_pack. + Sat Jun 8 09:49:42 2013 Tanaka Akira <akr@f...> * random.c (int_pair_to_real_inclusive): Use rb_integer_unpack. Index: random.c =================================================================== --- random.c (revision 41160) +++ random.c (revision 41161) @@ -302,21 +302,11 @@ int_pair_to_real_inclusive(uint32_t a, u https://github.com/ruby/ruby/blob/trunk/random.c#L302 #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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/