summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-10 10:37:39 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-10 10:37:39 +0000
commit0e8caa7d0f79c9514b4b4dbe9ac88b08e822e387 (patch)
tree4490705929fdb1765569a900d081e93c9f2d49f1 /bignum.c
parenta8aaf133921e5cfcf6e0ee88dc6b69e9c52ecf75 (diff)
* bignum.c (rb_integer_pack): Returns sign instead of words.
(absint_numwords_generic): Follow the above change. (big2str_base_powerof2): Follow the above change. * internal.h: Ditto. * hash.c (rb_hash): Ditto. * pack.c (pack_pack): Ditto. * random.c (int_pair_to_real_inclusive): Ditto. (rand_init): Ditto. (random_load): Ditto. (limited_big_rand): Ditto. * time.c (v2w_bignum): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/bignum.c b/bignum.c
index 8f2840d61d..9e02361d91 100644
--- a/bignum.c
+++ b/bignum.c
@@ -454,7 +454,7 @@ rb_big_unpack(unsigned long *buf, long num_longs)
/* number of bytes of abs(val). additionaly number of leading zeros can be returned. */
/*
- * Calculate a number of bytes to be required to represent
+ * Calculate the number of bytes to be required to represent
* the absolute value of the integer given as _val_.
*
* [val] an integer.
@@ -610,7 +610,7 @@ absint_numwords_generic(size_t numbytes, int nlz_bits_in_msbyte, size_t word_num
div = rb_funcall(div, '+', 1, LONG2FIX(1));
nlz_bits = word_numbits - NUM2SIZET(mod);
}
- rb_integer_pack(div, &sign, &numwords, 1, sizeof(numwords), 0,
+ sign = rb_integer_pack(div, &numwords, 1, sizeof(numwords), 0,
INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
if (sign == 2)
return (size_t)-1;
@@ -619,7 +619,7 @@ absint_numwords_generic(size_t numbytes, int nlz_bits_in_msbyte, size_t word_num
}
/*
- * Calculate a number of words to be required to represent
+ * Calculate the number of words to be required to represent
* the absolute value of the integer given as _val_.
*
* [val] an integer.
@@ -843,23 +843,25 @@ integer_pack_take_lowbits(int n, BDIGIT_DBL *ddp, int *numbits_in_dd_p)
/*
* Export an integer into a buffer.
*
- * [val] Fixnum, Bignum or another object which has to_int.
- * [signp] signedness is returned in *signp if it is not NULL.
- * 0 for zero.
- * -1 for negative without overflow. 1 for positive without overflow.
- * -2 for negative overflow. 2 for positive overflow.
+ * [val] Fixnum, Bignum or another integer like object which has to_int method.
* [words] buffer to export abs(val).
* [numwords] the size of given buffer as number of words.
* [wordsize] the size of word as number of bytes.
- * [nails] number of padding bits in a word. Most significant nails bits of each word are filled by zero.
- * [flags] bitwise or of constants which name starts "INTEGER_PACK_". It specifies word order and byte order.
- *
- * This function returns words or the allocated buffer if words is NULL.
+ * [nails] number of padding bits in a word.
+ * Most significant nails bits of each word are filled by zero.
+ * [flags] bitwise or of constants which name starts "INTEGER_PACK_".
+ * It specifies word order and byte order.
*
+ * This function returns the signedness and overflow condition as follows:
+ * -2 : negative overflow.
+ * -1 : negative without overflow.
+ * 0 : zero.
+ * 1 : positive without overflow.
+ * 2 : positive overflow.
*/
-void *
-rb_integer_pack(VALUE val, int *signp, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
+int
+rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
{
int sign;
BDIGIT *dp;
@@ -974,10 +976,7 @@ rb_integer_pack(VALUE val, int *signp, void *words, size_t numwords, size_t word
sign *= 2; /* overflow */
}
- if (signp)
- *signp = sign;
-
- return buf;
+ return sign;
#undef FILL_DD
#undef TAKE_LOWBITS
}
@@ -1055,8 +1054,12 @@ integer_unpack_push_bits(int data, int numbits, BDIGIT_DBL *ddp, int *numbits_in
* [words] buffer to import.
* [numwords] the size of given buffer as number of words.
* [wordsize] the size of word as number of bytes.
- * [nails] number of padding bits in a word. Most significant nails bits of each word are ignored.
- * [flags] bitwise or of constants which name starts "INTEGER_PACK_". It specifies word order and byte order.
+ * [nails] number of padding bits in a word.
+ * Most significant nails bits of each word are ignored.
+ * [flags] bitwise or of constants which name starts "INTEGER_PACK_".
+ * It specifies word order and byte order.
+ * Also, INTEGER_PACK_FORCE_BIGNUM specifies that the result will be a Bignum
+ * even if it is representable as a Fixnum.
*
* This function returns the imported integer as Fixnum or Bignum.
*/
@@ -1882,7 +1885,7 @@ big2str_base_powerof2(VALUE x, size_t len, int base, int trim)
result = rb_usascii_str_new(0, numwords);
ptr = RSTRING_PTR(result);
}
- rb_integer_pack(x, NULL, ptr, numwords, 1, CHAR_BIT-word_numbits,
+ rb_integer_pack(x, ptr, numwords, 1, CHAR_BIT-word_numbits,
INTEGER_PACK_BIG_ENDIAN);
while (0 < numwords) {
*ptr = ruby_digitmap[*(unsigned char *)ptr];