diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-11 21:39:55 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-11 21:39:55 +0000 |
commit | 0c9a719d7728e026e2bd4dfef61d940d3ca7248f (patch) | |
tree | abf593edd8848f8f9e18699b07a11aacb2389da8 /bignum.c | |
parent | a338c4ed5d519f05bf1f9fcd6a7b237a3101df0a (diff) |
* internal.h (INTEGER_PACK_NEGATIVE): Defined.
(rb_integer_unpack): sign argument removed.
* bignum.c (rb_integer_unpack): sign argument removed.
Non-negative integers generated by default.
INTEGER_PACK_NEGATIVE flag is used to generate non-positive integers.
* pack.c (pack_unpack): Follow the above change.
* random.c (int_pair_to_real_inclusive): Ditto.
(make_seed_value): Ditto.
(mt_state): Ditto.
(limited_big_rand): Ditto.
* marshal.c (r_object0): Ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -1178,8 +1178,6 @@ integer_unpack_push_bits(int data, int numbits, BDIGIT_DBL *ddp, int *numbits_in /* * Import an integer into a buffer. * - * [sign] signedness of the value. - * -1 for non-positive. 0 or 1 for non-negative. * [words] buffer to import. * [numwords] the size of given buffer as number of words. * [wordsize] the size of word as number of bytes. @@ -1187,17 +1185,20 @@ integer_unpack_push_bits(int data, int numbits, BDIGIT_DBL *ddp, int *numbits_in * 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. + * [INTEGER_PACK_FORCE_BIGNUM] the result will be a Bignum + * even if it is representable as a Fixnum. + * [INTEGER_PACK_NEGATIVE] Returns non-positive value. + * (Returns non-negative value if not specified.) * * This function returns the imported integer as Fixnum or Bignum. */ VALUE -rb_integer_unpack(int sign, const void *words, size_t numwords, size_t wordsize, size_t nails, int flags) +rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags) { VALUE result; const unsigned char *buf = words; size_t num_bdigits; + int sign = (flags & INTEGER_PACK_NEGATIVE) ? -1 : 1; BDIGIT *dp; BDIGIT *de; @@ -1215,8 +1216,6 @@ rb_integer_unpack(int sign, const void *words, size_t numwords, size_t wordsize, int numbits_in_dd; validate_integer_pack_format(numwords, wordsize, nails, flags); - if (sign != 1 && sign != 0 && sign != -1) - rb_raise(rb_eArgError, "unexpected sign: %d", sign); if (numwords <= (SIZE_MAX - (SIZEOF_BDIGITS*CHAR_BIT-1)) / CHAR_BIT / wordsize) { num_bdigits = integer_unpack_num_bdigits_small(numwords, wordsize, nails); |