Optimize bigdivrem1

e$BK-J!$G$9!#e(B

e$B8e$m$Ne(B zero e$B$,O"$J$C$F$$$kItJ,$N=hM}$r>J$-$^$9!#e(B
Bignum#to_s e$B$N4p?t$,#2$N$Y$->h$N$H$-$KHs>o$K8z2L$,$“$j$^$9!#e(B
e$B!J$b$C$H$be(B rb_big2str0
e$B$G4p?t$,#2$N$Y$->h$N$H$-$rJL=hM}$K$9$l$Pe(B
e$B$5$i$K7cB.$K$J$k$O$:$G$9$,!Ke(B
e$B4p?t$,#1#0$N$H$-$b$=$3$=$38z2L$”$j$^$9!#e(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;
    

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:36169] optimize bigdivrem1”
on Fri, 5 Sep 2008 21:13:54 +0900, TOYOFUKU Chikanobu
[email protected] writes:

| e$B8e$m$Ne(B zero e$B$,O"$J$C$F$$$kItJ,$N=hM}$r>J$-$^$9!#e(B
|Bignum#to_s e$B$N4p?t$,#2$N$Y$->h$N$H$-$KHs>o$K8z2L$,$“$j$^$9!#e(B
|e$B!J$b$C$H$be(B rb_big2str0 e$B$G4p?t$,#2$N$Y$->h$N$H$-$rJL=hM}$K$9$l$Pe(B
|e$B$5$i$K7cB.$K$J$k$O$:$G$9$,!Ke(B
|e$B4p?t$,#1#0$N$H$-$b$=$3$=$38z2L$”$j$^$9!#e(B

e$B<h$j9~$_$^$9!#B>$N%Q%C%A$b$$$$$$$H!#e(B