fix rounding on negative number shifting

avoid allocating unnecessary space.
This commit is contained in:
Vítor Santos Costa 2011-11-16 07:34:58 +00:00
parent fedf37ee35
commit c2504af4fb
1 changed files with 4 additions and 4 deletions

View File

@ -377,16 +377,16 @@ Yap_gmp_sll_big_int(Term t, Int i)
MP_INT *b = Yap_BigIntOfTerm(t); MP_INT *b = Yap_BigIntOfTerm(t);
if (i > 0) { if (i > 0) {
mpz_init_set(&new, b); mpz_init(&new);
mpz_mul_2exp(&new, &new, i); mpz_mul_2exp(&new, b, i);
} else if (i == 0) { } else if (i == 0) {
return t; return t;
} else { } else {
mpz_init_set(&new, b); mpz_init(&new);
if (i == Int_MIN) { if (i == Int_MIN) {
return Yap_ArithError(RESOURCE_ERROR_HUGE_INT, MkIntegerTerm(i), "<</2"); return Yap_ArithError(RESOURCE_ERROR_HUGE_INT, MkIntegerTerm(i), "<</2");
} }
mpz_tdiv_q_2exp(&new, &new, -i); mpz_fdiv_q_2exp(&new, b, -i);
} }
return MkBigAndClose(&new); return MkBigAndClose(&new);
} else { } else {