bignum.c (rb_int_powm): Integer#pow(0, 1) should return 0

... instead of 1 because it requires "modulo 1".  [Bug #17257]
This commit is contained in:
Yusuke Endoh 2020-10-12 13:42:48 +09:00
parent 1336698294
commit 8a39e6d653
2 changed files with 22 additions and 0 deletions

View file

@ -7136,6 +7136,7 @@ rb_int_powm(int const argc, VALUE * const argv, VALUE const num)
long const half_val = (long)HALF_LONG_MSB;
long const mm = FIX2LONG(m);
if (!mm) rb_num_zerodiv();
if (mm == 1) return INT2FIX(0);
if (mm <= half_val) {
return int_pow_tmp1(rb_int_modulo(a, m), b, mm, nega_flg);
}
@ -7145,6 +7146,7 @@ rb_int_powm(int const argc, VALUE * const argv, VALUE const num)
}
else {
if (rb_bigzero_p(m)) rb_num_zerodiv();
if (bignorm(m) == INT2FIX(1)) return INT2FIX(0);
return int_pow_tmp3(rb_int_modulo(a, m), b, m, nega_flg);
}
}