# Optimize bigdivrem1

**URL:** <https://www.ruby-forum.com/t/optimize-bigdivrem1/147790>\
**Category:** Development\
**Created:** [September 5, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/optimize-bigdivrem1/147790 "2008-09-05T14:20:01Z")\
**Posts on this page:** 2\
**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 5, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/optimize-bigdivrem1/147790/1 "2008-09-05T14:20:01Z")

</div>

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](http://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;

- 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;

```

* * *

---

<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 6, 2008, 12:18am UTC](https://www.ruby-forum.com/t/optimize-bigdivrem1/147790/2 "2008-09-06T00:18:05Z")

</div>

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  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
