diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2020-10-12 13:42:48 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2020-10-12 13:42:48 +0900 |
commit | 8a39e6d6539bd37100cbbfb88916b853f444f771 (patch) | |
tree | 5ea6f50cfa0f2cb92c4e7f6da341bed41e1105c6 /bignum.c | |
parent | 1336698294250ec78b4d33e0a52f8afb55e987d3 (diff) |
bignum.c (rb_int_powm): Integer#pow(0, 1) should return 0
... instead of 1 because it requires "modulo 1". [Bug #17257]
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -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); } } |