mruby-bigint: fix rounding behavior in mpz_mdiv and mpz_mdivmod functions

This commit is contained in:
Hoshiumi Arata
2024-12-11 21:09:46 +09:00
parent 9af061a4ce
commit 94a3a3eb6e
+2 -2
View File
@@ -590,7 +590,7 @@ mpz_mdiv(mrb_state *mrb, mpz_t *q, mpz_t *x, mpz_t *y)
q->sn = 0;
/* now if r != 0 and q < 0 we need to round q towards -inf */
if (!uzero_p(&r) && qsign < 0)
mpz_sub_int(mrb, q, 1);
mpz_add_int(mrb, q, 1);
mpz_clear(mrb, &r);
}
@@ -655,7 +655,7 @@ mpz_mdivmod(mrb_state *mrb, mpz_t *q, mpz_t *r, mpz_t *x, mpz_t *y)
q->sn = 0;
/* now if r != 0 and q < 0 we need to round q towards -inf */
if (!uzero_p(r) && qsign < 0)
mpz_sub_int(mrb, q, 1);
mpz_add_int(mrb, q, 1);
}
static void