[前][次][番号順一覧][スレッド一覧]

ruby-changes:29113

From: akr <ko1@a...>
Date: Sat, 8 Jun 2013 15:00:23 +0900 (JST)
Subject: [ruby-changes:29113] akr:r41165 (trunk): * internal.h (INTEGER_PACK_FORCE_BIGNUM): New flag constant.

akr	2013-06-08 15:00:04 +0900 (Sat, 08 Jun 2013)

  New Revision: 41165

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41165

  Log:
    * internal.h (INTEGER_PACK_FORCE_BIGNUM): New flag constant.
    
    * bignum.c (rb_integer_unpack): Support INTEGER_PACK_FORCE_BIGNUM.
    
    * random.c (int_pair_to_real_inclusive): Use
      INTEGER_PACK_FORCE_BIGNUM to use rb_big_mul instead of rb_funcall.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/internal.h
    trunk/random.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41164)
+++ ChangeLog	(revision 41165)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun  8 14:58:32 2013  Tanaka Akira  <akr@f...>
+
+	* internal.h (INTEGER_PACK_FORCE_BIGNUM): New flag constant.
+
+	* bignum.c (rb_integer_unpack): Support INTEGER_PACK_FORCE_BIGNUM.
+
+	* random.c (int_pair_to_real_inclusive): Use
+	  INTEGER_PACK_FORCE_BIGNUM to use rb_big_mul instead of rb_funcall. 
+
 Sat Jun  8 14:17:01 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in: check for NET_LUID.  header macro varies across
Index: internal.h
===================================================================
--- internal.h	(revision 41164)
+++ internal.h	(revision 41165)
@@ -55,11 +55,15 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L55
 
 /* "MS" in MSWORD and MSBYTE means "most significant" */
 /* "LS" in LSWORD and LSBYTE means "least significant" */
+/* For rb_integer_pack and rb_integer_unpack: */
 #define INTEGER_PACK_MSWORD_FIRST       0x01
 #define INTEGER_PACK_LSWORD_FIRST       0x02
 #define INTEGER_PACK_MSBYTE_FIRST       0x10
 #define INTEGER_PACK_LSBYTE_FIRST       0x20
 #define INTEGER_PACK_NATIVE_BYTE_ORDER  0x40
+/* For rb_integer_unpack: */
+#define INTEGER_PACK_FORCE_BIGNUM       0x100
+/* Combinations: */
 #define INTEGER_PACK_LITTLE_ENDIAN \
     (INTEGER_PACK_LSWORD_FIRST | \
      INTEGER_PACK_LSBYTE_FIRST)
Index: bignum.c
===================================================================
--- bignum.c	(revision 41164)
+++ bignum.c	(revision 41165)
@@ -932,6 +932,8 @@ rb_integer_unpack(int sign, const void * https://github.com/ruby/ruby/blob/trunk/bignum.c#L932
     while (dp < de)
         *dp++ = 0;
 
+    if (flags & INTEGER_PACK_FORCE_BIGNUM)
+        return bigtrunc(result);
     return bignorm(result);
 #undef PUSH_BITS
 }
Index: random.c
===================================================================
--- random.c	(revision 41164)
+++ random.c	(revision 41165)
@@ -285,15 +285,17 @@ int_pair_to_real_inclusive(uint32_t a, u https://github.com/ruby/ruby/blob/trunk/random.c#L285
     xary[0] = a;
     xary[1] = b;
     x = rb_integer_unpack(+1, xary, 2, sizeof(uint32_t), 0,
-        INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
+        INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER|
+        INTEGER_PACK_FORCE_BIGNUM);
 
     /* (1 << 53) | 1 */
     mary[0] = 0x00200000;
     mary[1] = 0x00000001;
     m = rb_integer_unpack(+1, mary, 2, sizeof(uint32_t), 0,
-        INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
+        INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER|
+        INTEGER_PACK_FORCE_BIGNUM);
 
-    x = rb_funcall(x, '*', 1, m);
+    x = rb_big_mul(x, m);
     if (FIXNUM_P(x)) {
 #if CHAR_BIT * SIZEOF_LONG > 64
 	r = (double)(FIX2ULONG(x) >> 64);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]