diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-05 12:17:30 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-05 12:17:30 +0000 |
commit | 13bba43d641a0f7042264a800902f5105cc7d3c6 (patch) | |
tree | 6312474c55997a329e28dbb1e3ad1c86bc096257 | |
parent | 4a97761c1a571e9475c782b758e513cfe6a505ae (diff) | |
download | ruby-13bba43d641a0f7042264a800902f5105cc7d3c6.tar.gz |
* bignum.c (big_fdiv): Use nlz() instead of bdigbitsize().
(bdigbitsize): Removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bignum.c | 31 |
2 files changed, 9 insertions, 27 deletions
@@ -1,3 +1,8 @@ +Wed Jun 5 21:17:08 2013 Tanaka Akira <akr@fsij.org> + + * bignum.c (big_fdiv): Use nlz() instead of bdigbitsize(). + (bdigbitsize): Removed. + Wed Jun 5 20:32:00 2013 Kenta Murata <mrkn@cookpad.com> * include/ruby/ruby.h: fix alignment in comment. @@ -3050,27 +3050,6 @@ rb_big_divmod(VALUE x, VALUE y) return rb_assoc_new(bignorm(div), bignorm(mod)); } -static int -bdigbitsize(BDIGIT x) -{ - int size = 1; - int nb = BITSPERDIG / 2; - BDIGIT bits = (~0 << nb); - - if (!x) return 0; - while (x > 1) { - if (x & bits) { - size += nb; - x >>= nb; - } - x &= ~bits; - nb /= 2; - bits >>= nb; - } - - return size; -} - static VALUE big_shift(VALUE x, long n) { @@ -3090,9 +3069,8 @@ big_fdiv(VALUE x, VALUE y) int i; bigtrunc(x); - l = RBIGNUM_LEN(x) - 1; - ex = l * BITSPERDIG; - ex += bdigbitsize(BDIGITS(x)[l]); + l = RBIGNUM_LEN(x); + ex = l * BITSPERDIG - nlz(BDIGITS(x)[l-1]); ex -= 2 * DBL_BIGDIG * BITSPERDIG; if (ex) x = big_shift(x, ex); @@ -3101,9 +3079,8 @@ big_fdiv(VALUE x, VALUE y) y = rb_int2big(FIX2LONG(y)); case T_BIGNUM: bigtrunc(y); - l = RBIGNUM_LEN(y) - 1; - ey = l * BITSPERDIG; - ey += bdigbitsize(BDIGITS(y)[l]); + l = RBIGNUM_LEN(y); + ey = l * BITSPERDIG - nlz(BDIGITS(y)[l-1]); ey -= DBL_BIGDIG * BITSPERDIG; if (ey) y = big_shift(y, ey); break; |