Project

General

Profile

Actions

Bug #18993

closed

Inconsistent Range#size for Float and Rational

Added by masasakano (Masa Sakano) about 2 years ago. Updated 8 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
[ruby-core:109826]

Description

The returned values of Range#size between Rational and Float and also with regard to exclude_end of true and false are inconsistent.

The example below highlights the difference. The first and second should return the same value. The difference between the first and third seems strange - if this is the specification, it should be clearly described in the doc. This point may be related to the issue "Misc #18984".

(5.quo(3)...5).size      # => 3
(5.quo(3).to_f...5).size # => 4
(5.quo(3)..5).size       # => 4
(5.quo(3).to_f..5).size  # => 4

Updated by jeremyevans0 (Jeremy Evans) 8 months ago

  • Status changed from Open to Closed

This appears fixed in Ruby 3.3:

$ ruby32 -ve "p (5.quo(3)...5).size"
ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-openbsd]
3

$ ruby33 -ve "p (5.quo(3)...5).size"
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-openbsd]
4
Actions

Also available in: Atom PDF

Like1
Like0