From: universato@... Date: 2020-10-11T18:46:38+00:00 Subject: [ruby-core:100375] [Ruby master Bug#17257] Integer#pow(0, 1) returns 1, which is incorrect Issue #17257 has been updated by universato (Yoshimine Sato). sawa (Tsuyoshi Sawada) wrote in #note-10: > I cannot follow the discussion because of the expression "multiplying `x % m` to 1 `y` times." What does that mean? "multiplying x % m to 1 y times"������������������1������������(x % m)���y������������������(������������������)������������������ ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ nobu���������������������#1������x.pow(y, m)���1���(x % m)���y������������������������������������y == 0������������1��������������������������������������������������������������� ���������������������#9���������������������`3.pow(2, 4)`���1���������������`1���(3 % 4)`���2������������������9������������������`x.pow(y, m)`���1���`(x % m)`���`y`���������������������������������������������������pow������������������m������������������������������x.pow(0, 1)������������������������������������������������������������������`(x**y) % m`������`x.pow(0, 1)`������������������1��������������������������������������������������������������������������������������������������������������������������������� midnight���������#7���������������������������������������������������������"1������������`(x % m)`���`y`������������������"���������������������������������������������������`% m`���������������������������������������������������������������������������������������������������������������������������(���`m`���������������������)��������������������������� ...... ������������������������������������mod 1���������������������������������������������������������������������������������������������������������mod������������������������������������������1������������������������������������������������������������mod 1���������������������0������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������x.pow(0, 1)���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������`if(m == 1){ return 0 }`���������������������������������������������������������������������������������������������������mrkn������������������������������������������������������������������������������Python���mod_pow������������������������������������������������������������������������������ Sorry for writing only in Japanese ---------------------------------------- Bug #17257: Integer#pow(0, 1) returns 1, which is incorrect https://bugs.ruby-lang.org/issues/17257#change-87986 * Author: universato (Yoshimine Sato) * Status: Assigned * Priority: Normal * Assignee: mrkn (Kenta Murata) * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- Ruby 2.5.8, 2.6.6, 2.7.1 ```ruby p -1.pow(0, 1) #=> 1 p 0.pow(0, 1) #=> 1 p 1.pow(0, 1) #=> 1 p 1234567890.pow(0, 1) #=> 1 ``` These return values should be 0. Patch for test: Let's add some boundary value tests to `test_pow` of [test_numeric.rb](https://github.com/ruby/ruby/blob/e014e6bf6685f681998238ff005f6d161d43ce51/test/ruby/test_numeric.rb). ```ruby integers = [-2, -1, 0, 1, 2, 3, 6, 1234567890123456789] integers.each do |i| assert_equal(0, i.pow(0, 1), '[Bug #17257]') assert_equal(1, i.pow(0, 2)) assert_equal(1, i.pow(0, 3)) assert_equal(1, i.pow(0, 6)) assert_equal(1, i.pow(0, 1234567890123456789)) assert_equal(0, i.pow(0, -1)) assert_equal(-1, i.pow(0, -2)) assert_equal(-2, i.pow(0, -3)) assert_equal(-5, i.pow(0, -6)) assert_equal(-1234567890123456788, i.pow(0, -1234567890123456789)) end assert_equal(0, 0.pow(2, 1)) assert_equal(0, 0.pow(3, 1)) assert_equal(0, 2.pow(3, 1)) assert_equal(0, -2.pow(3, 1)) -- https://bugs.ruby-lang.org/ Unsubscribe: