# Optimize bigdivrem Part 4

**URL:** <https://www.ruby-forum.com/t/optimize-bigdivrem-part-4/148121>\
**Category:** Development\
**Created:** [September 9, 2008, 3:30pm UTC](https://www.ruby-forum.com/t/optimize-bigdivrem-part-4/148121 "2008-09-09T15:30:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TOYOFUKU\_Chikanobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@TOYOFUKU\_Chikanobu](https://www.ruby-forum.com/u/TOYOFUKU_Chikanobu)\
**Post date:** [September 9, 2008, 3:30pm UTC](https://www.ruby-forum.com/t/optimize-bigdivrem-part-4/148121/1 "2008-09-09T15:30:40Z")

</div>

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

big2str\_karatsuba e$B$Ge(B bigdivmod e$B$K$h$j5a$a$?\>&$HM\>$j$Ne(B  
Bignum  
e$B$ND9$5$,:GE,$JD9$5$H?)$$0c$o$J$$$h$&$K$7$^$9!#e(B  
e$B8=:\_$3$N?)$$0c$$$,$"$C$F$b9,$$LdBj$O5/$-$^$;$s$,8=\>u$,K\>$^$7$$e(B  
e$B$H$O;W$($J$$$N$G=$@5$rDs0F$7$^$9!#e(B

— [bignum.c.org](http://bignum.c.org)  
+++ bignum.c  
@@ -1764,6 +1752,7 @@  
zds = BDIGITS(\*divp);  
j = (nx==ny ? nx+2 : nx+1) - ny;  
for (i = 0;i \< j;i++) zds[i] = zds[i+ny];

- 

```
  if (!zds[i-1]) i--;
  RBIGNUM_SET_LEN(*divp, i);

```

}  
if (modp) { /\* normalize remainder \*/  
@@ -1779,6 +1768,7 @@  
t2 = BIGUP(q);  
}  
}
- 

```
  if (!zds[ny-1]) ny--;
  RBIGNUM_SET_LEN(*modp, ny);
  RBIGNUM_SET_SIGN(*modp, RBIGNUM_SIGN(x));

```

}

* * *
