Commit ce85868a authored by Ken Thompson's avatar Ken Thompson

bug in const float divide

R=rsc
CC=golang-dev
https://golang.org/cl/204042
parent 072b560e
...@@ -618,6 +618,19 @@ mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d) ...@@ -618,6 +618,19 @@ mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d)
q->neg = ns^ds; q->neg = ns^ds;
} }
int
iszero(Mpint *a)
{
long *a1;
int i;
a1 = &a->a[0] + Mpprec;
for(i=0; i<Mpprec; i++) {
if(*--a1 != 0)
return 0;
}
return 1;
}
void void
mpdivfract(Mpint *a, Mpint *b) mpdivfract(Mpint *a, Mpint *b)
{ {
...@@ -632,12 +645,12 @@ mpdivfract(Mpint *a, Mpint *b) ...@@ -632,12 +645,12 @@ mpdivfract(Mpint *a, Mpint *b)
neg = n.neg ^ d.neg; neg = n.neg ^ d.neg;
n.neg = 0; n.neg = 0;
d.neg = 0; d.neg = 0;
for(i=0; i<Mpprec; i++) { for(i=0; i<Mpprec; i++) {
x = 0; x = 0;
for(j=0; j<Mpscale; j++) { for(j=0; j<Mpscale; j++) {
x <<= 1; x <<= 1;
if(mpcmp(&d, &n) <= 0) { if(mpcmp(&d, &n) <= 0) {
if(!iszero(&d))
x |= 1; x |= 1;
mpsubfixfix(&n, &d); mpsubfixfix(&n, &d);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment