mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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:
parent
1336698294
commit
8a39e6d653
2 changed files with 22 additions and 0 deletions
2
bignum.c
2
bignum.c
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue