diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-25 10:04:37 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-25 10:04:37 +0000 |
commit | a8c226922de30f0a371959bba4e77b03497c7b9d (patch) | |
tree | 577faa4d027910768aa3af541657ea3e683c952e /bignum.c | |
parent | 6dede5115910bd88a0addc36349376735ee93949 (diff) | |
download | ruby-a8c226922de30f0a371959bba4e77b03497c7b9d.tar.gz |
* bignum.c (big2ulong): Add a cast.
(big2ull): Add a specialized code for SIZEOF_LONG_LONG <=
SIZEOF_BDIGITS.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -2423,7 +2423,7 @@ big2ulong(VALUE x, const char *type, int check) } ds = BDIGITS(x); #if SIZEOF_LONG <= SIZEOF_BDIGITS - num = ds[0]; + num = (unsigned long)ds[0]; #else num = 0; while (len--) { @@ -2486,16 +2486,21 @@ big2ull(VALUE x, const char *type) { long len = RBIGNUM_LEN(x); unsigned LONG_LONG num; - BDIGIT *ds; + BDIGIT *ds = BDIGITS(x); - if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) + if (len == 0) + return 0; + if (BIGSIZE(x) > SIZEOF_LONG_LONG) rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type); - ds = BDIGITS(x); +#if SIZEOF_LONG_LONG <= SIZEOF_BDIGITS + num = (unsigned LONG_LONG)ds[0]; +#else num = 0; while (len--) { num = BIGUP(num); num += ds[len]; } +#endif return num; } |