aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 06:00:04 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 06:00:04 +0000
commit0056591f50502c58616f3ea5249e92a174ab86c6 (patch)
tree59a61fc85117795830079293353fdc2967596636
parent4d6ac81117360a3b11f6a950ae1776a24bc49bcc (diff)
downloadruby-0056591f50502c58616f3ea5249e92a174ab86c6.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--bignum.c2
-rw-r--r--internal.h4
-rw-r--r--random.c8
4 files changed, 20 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 53e14379b5..141511b91c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jun 8 14:58:32 2013 Tanaka Akira <akr@fsij.org>
+
+ * 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@ruby-lang.org>
* configure.in: check for NET_LUID. header macro varies across
diff --git a/bignum.c b/bignum.c
index a791968dd4..1c92117669 100644
--- a/bignum.c
+++ b/bignum.c
@@ -932,6 +932,8 @@ rb_integer_unpack(int sign, const void *words, size_t numwords, size_t wordsize,
while (dp < de)
*dp++ = 0;
+ if (flags & INTEGER_PACK_FORCE_BIGNUM)
+ return bigtrunc(result);
return bignorm(result);
#undef PUSH_BITS
}
diff --git a/internal.h b/internal.h
index 6d4f8d417e..3b091e503e 100644
--- a/internal.h
+++ b/internal.h
@@ -55,11 +55,15 @@ extern "C" {
/* "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)
diff --git a/random.c b/random.c
index bfb961019c..b9869f9b11 100644
--- a/random.c
+++ b/random.c
@@ -285,15 +285,17 @@ int_pair_to_real_inclusive(uint32_t a, uint32_t b)
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);