summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-05 12:17:30 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-05 12:17:30 +0000
commit13bba43d641a0f7042264a800902f5105cc7d3c6 (patch)
tree6312474c55997a329e28dbb1e3ad1c86bc096257 /bignum.c
parent4a97761c1a571e9475c782b758e513cfe6a505ae (diff)
* 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
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c31
1 files changed, 4 insertions, 27 deletions
diff --git a/bignum.c b/bignum.c
index 5c7fc1ea8d..a304c9324d 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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;