$BK-J!$G$9!#(B
$B8e$m$N(B zero $B$,O"$J$C$F$$$kItJ,$N=hM}$r>J$-$^$9!#(B
Bignum#to_s $B$N4p?t$,#2$N$Y$->h$N$H$-$KHs>o$K8z2L$,$"$j$^$9!#(B
$B!J$b$C$H$b(B rb_big2str0
$B$G4p?t$,#2$N$Y$->h$N$H$-$rJL=hM}$K$9$l$P(B
$B$5$i$K7cB.$K$J$k$O$:$G$9$,!K(B
$B4p?t$,#1#0$N$H$-$b$=$3$=$38z2L$"$j$^$9!#(B
--- bignum.c.org
+++ bignum.c
@@ -1633,19 +1633,20 @@
{
struct big_div_struct *bds = (struct big_div_struct*)ptr;
long nx = bds->nx, ny = bds->ny;
- long i, j;
+ long i, j, nyzero;
BDIGIT *yds = bds->yds, *zds = bds->zds;
BDIGIT_DBL t2;
BDIGIT_DBL_SIGNED num;
BDIGIT q;
j = nx==ny?nx+1:nx;
+ for (nyzero = 0; !yds[nyzero]; nyzero++);
do {
if (bds->stop) return Qnil;
if (zds[j] == yds[ny-1]) q = BIGRAD-1;
else q = (BDIGIT)((BIGUP(zds[j]) + zds[j-1])/yds[ny-1]);
if (q) {
- i = 0; num = 0; t2 = 0;
+ i = nyzero; num = 0; t2 = 0;
do { /* multiply and subtract */
BDIGIT_DBL ee;
t2 += (BDIGIT_DBL)yds[i] * q;
---
on 05.09.2008 14:20
on 06.09.2008 00:18
$B$^$D$b$H(B $B$f$-$R$m$G$9(B
In message "Re: [ruby-dev:36169] optimize bigdivrem1"
on Fri, 5 Sep 2008 21:13:54 +0900, TOYOFUKU Chikanobu
<nobu_toyofuku@nifty.com> writes:
| $B8e$m$N(B zero $B$,O"$J$C$F$$$kItJ,$N=hM}$r>J$-$^$9!#(B
|Bignum#to_s $B$N4p?t$,#2$N$Y$->h$N$H$-$KHs>o$K8z2L$,$"$j$^$9!#(B
|$B!J$b$C$H$b(B rb_big2str0 $B$G4p?t$,#2$N$Y$->h$N$H$-$rJL=hM}$K$9$l$P(B
|$B$5$i$K7cB.$K$J$k$O$:$G$9$,!K(B
|$B4p?t$,#1#0$N$H$-$b$=$3$=$38z2L$"$j$^$9!#(B
$B<h$j9~$_$^$9!#B>$N%Q%C%A$b$*$$$*$$$H!#(B