From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id E0B5D1F5AE for ; Wed, 15 Jul 2020 15:59:07 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2085A120A5E; Thu, 16 Jul 2020 00:58:35 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 811EF120A57 for ; Thu, 16 Jul 2020 00:58:32 +0900 (JST) Received: by filterdrecv-p3mdw1-75c584b9c6-55xs5 with SMTP id filterdrecv-p3mdw1-75c584b9c6-55xs5-19-5F0F27C2-5B 2020-07-15 15:58:58.515130209 +0000 UTC m=+1637365.742671085 Received: from herokuapp.com (unknown) by ismtpd0036p1iad1.sendgrid.net (SG) with ESMTP id r9iO8FKGQKGCsyGUH_r3DA for ; Wed, 15 Jul 2020 15:58:58.445 +0000 (UTC) Date: Wed, 15 Jul 2020 15:58:58 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74969 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17017 X-Redmine-Issue-Author: sambostock X-Redmine-Sender: jeremyevans0 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BI4eZrc3PKwAtpmfAc+v0nTFQ6VfIUg8Yz6980B?= =?us-ascii?Q?tT5u7boIiyEM=2FyekNgCX5un6YkQb8vjqkNlRFVA?= =?us-ascii?Q?t7hkZ5NnUCm4acnPb9hbhcnYNTI=2FSzxd=2FwBpTGp?= =?us-ascii?Q?FdHC3qdocXJsxyKBhsLWBfnxX=2Fkul+MsKyreabx?= =?us-ascii?Q?oy4is9TjeaKANsFqY=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99179 Subject: [ruby-core:99179] [Ruby master Bug#17017] Range#max & Range#minmax incorrectly use Float end as max X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17017 has been updated by jeremyevans0 (Jeremy Evans). marcandre (Marc-Andre Lafortune) wrote in #note-9: > jeremyevans0 (Jeremy Evans) wrote in #note-7: > > koic (Koichi ITO) wrote in #note-6: > > > I encountered a breaking change in RuboCop repository when using ruby 2.8.0dev. > > > https://github.com/rubocop-hq/rubocop/blob/v0.88.0/lib/rubocop/comment_config.rb#L110 > > > > > > So, I have a question. Is this an expected behaviour? > > > > Yes, it is expected behavior, at least to me. I believe the Ruby 2.7 behavior is wrong, because a range that starts with an integer will never have a non-integer maximum value, since the increment is an integer. > > I should have been more clear when I commented to take care of Infinity, but I believe that previous behavior should remain. Since there is no `Integer::INFINITY`, returning `Float::INFINITY` is quite descriptive and useful. Raising a `RangeError` doesn't seem helpful. (I wrote `RangeError` since raising `FloatDomainError` as currently is definitely a mistake). With current Ruby, you should use an endless range instead of range with an infinite end. The previous behavior of returning `Float::INFINITY` seems wrong to me. I suppose the current behavior of raising `FloatDomainError` may be unexpected, and `RangeError` could be returned instead. Note that if you use the exclusive range (`42...Float::INFINITY`), you would get a `TypeError` in 2.7.1, so it's not like we exclusively used `RangeError` for issues like these. Mathematically, `42..Float::INFINITY` and `42...Float::INFINITY` represent the same range, so you should get the same behavior for both. All that said, I'm not completely opposed to special casing `Float::INFINITY` in this case. I would like to hear opinions from other committers. ---------------------------------------- Bug #17017: Range#max & Range#minmax incorrectly use Float end as max https://bugs.ruby-lang.org/issues/17017#change-86558 * Author: sambostock (Sam Bostock) * Status: Open * Priority: Normal * ruby -v: ruby 2.8.0dev (2020-07-14T04:19:55Z master e60cd14d85) [x86_64-darwin17] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- While continuing to add edge cases to [`Range#minmax` specs](https://github.com/ruby/spec/pull/777), I discovered the following bug: ```ruby (1..3.1).to_a == [1, 2, 3] # As expected (1..3.1).to_a.max == 3 # As expected (1..3.1).to_a.minmax == [1, 3] # As expected (1..3.1).max == 3.1 # Should be 3, as above (1..3.1).minmax == [1, 3.1] # Should be [1, 3], as above ``` One way to detect this scenario might be to do (whatever the C equivalent is of) ```ruby range_end.is_a?(Numeric) // Is this a numeric range? && (range_end - range_begin).modulo(1) == 0 // Can we reach the range_end using the standard step size (1) ``` As for how to handle it, a couple options come to mind: - We could error out and do something similar to what we do for exclusive ranges ```ruby raise TypeError, 'cannot exclude non Integer end value' ``` - We might be able to calculate the range end by doing something like ```ruby num_steps = (range_end / range_beg).to_i - 1 # one fewer steps than would exceed the range_end max = range_beg + num_steps # take that many steps all at once ``` - We could delegate to `super` and enumerate the range to find the max ```ruby super ``` - We could update the documentation to define the max for this case as the `range_end`, similarly to how the documentation for `include?` says it behaves like `cover?` for numeric ranges. -- https://bugs.ruby-lang.org/