bigint.c (mrb_bint_powm): fix a return value bug.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-08-26 12:13:24 +09:00
parent ef1974099d
commit b4785044d5
+8 -8
View File
@@ -1382,17 +1382,17 @@ mrb_bint_powm(mrb_state *mrb, mrb_value x, mrb_int exp, mrb_value mod)
{
mrb_int m = mrb_integer(mod);
if (m == 0) mrb_int_zerodiv(mrb);
struct RBigint *b2 = bint_new(mrb);
struct RBigint *b3 = bint_new_int(mrb, m);
mpz_powm(mrb, &b2->mp, &b->mp, exp, &b3->mp);
return mrb_obj_value(b3);
struct RBigint *b2 = bint_new_int(mrb, m);
struct RBigint *b3 = bint_new(mrb);
mpz_powm(mrb, &b3->mp, &b->mp, exp, &b2->mp);
return bint_norm(mrb, b3);
}
case MRB_TT_BIGINT:
{
struct RBigint *b2 = bint_new(mrb);
struct RBigint *b3 = RBIGINT(mod);
if (uzero(&b3->mp)) mrb_int_zerodiv(mrb);
mpz_powm(mrb, &b2->mp, &b->mp, exp, &b3->mp);
struct RBigint *b2 = RBIGINT(mod);
struct RBigint *b3 = bint_new(mrb);
if (uzero(&b2->mp)) mrb_int_zerodiv(mrb);
mpz_powm(mrb, &b3->mp, &b->mp, exp, &b2->mp);
return bint_norm(mrb, b3);
}
mrb_raise(mrb, E_TYPE_ERROR, "too big power");