mpdiv: fix dividing 0 by a small power of two
This commit is contained in:
parent
69298c79ab
commit
e87ca8d976
1 changed files with 3 additions and 1 deletions
|
@ -22,7 +22,9 @@ mpdiv(mpint *dividend, mpint *divisor, mpint *quotient, mpint *remainder)
|
||||||
|
|
||||||
// division by one or small powers of two
|
// division by one or small powers of two
|
||||||
if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){
|
if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){
|
||||||
vlong r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1);
|
vlong r = 0;
|
||||||
|
if(dividend->top > 0)
|
||||||
|
r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1);
|
||||||
if(quotient != nil){
|
if(quotient != nil){
|
||||||
sign = divisor->sign;
|
sign = divisor->sign;
|
||||||
for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++)
|
for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++)
|
||||||
|
|
Loading…
Reference in a new issue