fix div to round correctly (Ulrich's #181).
This commit is contained in:
parent
afa0799504
commit
3cfe5c74d5
@ -111,7 +111,7 @@ p_div2(Term t1, Term t2) {
|
|||||||
{
|
{
|
||||||
Int i1 = IntegerOfTerm(t1);
|
Int i1 = IntegerOfTerm(t1);
|
||||||
Int i2 = IntegerOfTerm(t2);
|
Int i2 = IntegerOfTerm(t2);
|
||||||
Int res;
|
Int res, mod;
|
||||||
|
|
||||||
if (i2 == 0) goto zero_divisor;
|
if (i2 == 0) goto zero_divisor;
|
||||||
if (i1 == Int_MIN && i2 == -1) {
|
if (i1 == Int_MIN && i2 == -1) {
|
||||||
@ -122,7 +122,10 @@ p_div2(Term t1, Term t2) {
|
|||||||
"// /2 with %d and %d", i1, i2);
|
"// /2 with %d and %d", i1, i2);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
res = (i1 - i1%i2) / i2;
|
mod = i1%i2;
|
||||||
|
if (mod && (mod ^ i2) < 0)
|
||||||
|
mod += i2;
|
||||||
|
res = (i1 - mod) / i2;
|
||||||
RINT(res);
|
RINT(res);
|
||||||
}
|
}
|
||||||
case (CELL)double_e:
|
case (CELL)double_e:
|
||||||
|
Reference in New Issue
Block a user