ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: universato@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:100348] [Ruby master Bug#17257] Integer#pow(0, 1) returns 1, which is incorrect
Date: Fri, 09 Oct 2020 14:18:43 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-17257.20201009141843.45098@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17257.20201009141843.45098@ruby-lang.org

Issue #17257 has been reported by universato (Yoshimine Sato).

----------------------------------------
Bug #17257: Integer#pow(0, 1) returns 1, which is incorrect
https://bugs.ruby-lang.org/issues/17257

* Author: universato (Yoshimine Sato)
* Status: Open
* Priority: Normal
* 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 value shoud 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/

       reply	other threads:[~2020-10-09 14:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09 14:18 universato [this message]
2020-10-10  6:54 ` [ruby-core:100355] [Ruby master Bug#17257] Integer#pow(0, 1) returns 1, which is incorrect nobu
2020-10-10  9:18 ` [ruby-core:100356] " universato
2020-10-10 18:12 ` [ruby-core:100359] " midnight_w
2020-10-10 19:28 ` [ruby-core:100361] " marcandre-ruby-core
2020-10-11  2:48 ` [ruby-core:100363] " nobu
2020-10-11  3:32 ` [ruby-core:100365] " midnight_w
2020-10-11  3:41 ` [ruby-core:100366] " midnight_w
2020-10-11  5:54 ` [ruby-core:100367] " universato
2020-10-11 12:09 ` [ruby-core:100373] " sawadatsuyoshi
2020-10-11 13:18 ` [ruby-core:100374] " midnight_w
2020-10-11 18:46 ` [ruby-core:100375] " universato
2020-10-12  4:35 ` [ruby-core:100379] " mame

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-17257.20201009141843.45098@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).