fix div to round correctly (Ulrich's #181).

This commit is contained in:
Vitor Santos Costa 2010-10-08 10:58:08 +01:00
parent afa0799504
commit 3cfe5c74d5

View File

@ -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: