diff --git a/ChangeLog b/ChangeLog index a5b0d13281..44abc85b34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Jun 25 19:03:00 2013 Tanaka Akira + + * bignum.c (big2ulong): Add a cast. + (big2ull): Add a specialized code for SIZEOF_LONG_LONG <= + SIZEOF_BDIGITS. + Tue Jun 25 12:42:57 2013 Tanaka Akira * bignum.c (integer_unpack_single_bdigit): Use "1 + ~u" instead of diff --git a/bignum.c b/bignum.c index 53a9ad5c8a..78fd02fb7a 100644 --- a/bignum.c +++ b/bignum.c @@ -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; }