https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-04-15T07:23:33ZRuby Issue Tracking SystemRuby master - Bug #4577: (int...float).max should not raise an errorhttps://redmine.ruby-lang.org/issues/4577?journal_id=164992011-04-15T07:23:33Ztarui (Masaya Tarui)tarui@prx.jp
<ul><li><strong>ruby -v</strong> changed from <i>ruby 1.9.2p180 (2011-02-18) [i386-mingw32]</i> to <i>-</i></li></ul><p>=begin<br>
Hi,</p>
<p>I feel that 1.8's Range#max is good.</p>
<p>1.9's Range#max sometimes does strange behavior.</p>
<blockquote>
<p>irb<br>
irb(main):001:0> RUBY_DESCRIPTION<br>
=> "ruby 1.9.3dev (2011-04-11 trunk 31261) [i386-mswin32_100]"<br>
irb(main):002:0> (1..1.2).max<br>
=> 1.2<br>
irb(main):003:0> (1...1.2).max<br>
TypeError: cannot exclude non Integer end value<br>
irb(main):004:0> (1.1..3.2).max<br>
=> 3.2<br>
irb(main):005:0> (1.1..2).max<br>
=> 2<br>
irb(main):006:0> (1.1...2).max<br>
=> 1</p>
</blockquote>
<p>(1.1...2).max is 1 ?!!!<br>
I cannot think it is correct result.</p>
<p>Here is 1.8's</p>
<p>irb(main):001:0> RUBY_DESCRIPTION<br>
=> "ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]"<br>
irb(main):002:0> (1..1.2).max<br>
=> 1<br>
irb(main):003:0> (1...1.2).max<br>
=> 1<br>
irb(main):004:0> (1.1..3.2).max<br>
TypeError: can't iterate from Float<br>
irb(main):005:0> (1.1..2).max<br>
TypeError: can't iterate from Float<br>
irb(main):006:0> (1.1...2).max<br>
TypeError: can't iterate from Float</p>
<p>Here is better though it is sad not to be able to treat Float.</p>
<a name="btw-I-have-used-Range-only-with-Integer-"></a>
<h2 >btw, I have used Range only with Integer :-)<a href="#btw-I-have-used-Range-only-with-Integer-" class="wiki-anchor">¶</a></h2>
<p>Masaya TARUI<br>
No Tool,No Life.<br>
=end</p> Ruby master - Bug #4577: (int...float).max should not raise an errorhttps://redmine.ruby-lang.org/issues/4577?journal_id=165012011-04-15T09:23:27Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>=begin<br>
Hi,</p>
<p>In message "Re: <a href="/issues/4577">[ruby-core:35754]</a> [Ruby 1.9 - Bug <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: (int...float).max should not raise an error (Rejected)" href="https://redmine.ruby-lang.org/issues/4577">#4577</a>][Open] (int...float).max should not raise an error"</p>
<table>
<thead>
<tr>
<th>on Fri, 15 Apr 2011 00:02:07 +0900, <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> writes:</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug <a class="issue tracker-1 status-6 priority-4 priority-default closed" title="Bug: (int...float).max should not raise an error (Rejected)" href="https://redmine.ruby-lang.org/issues/4577">#4577</a>: (int...float).max should not raise an error</td>
</tr>
<tr>
<td><a href="http://redmine.ruby-lang.org/issues/4577" class="external">http://redmine.ruby-lang.org/issues/4577</a></td>
</tr>
</tbody>
</table>
<p>|(int...float).max (without a block) will raise an error:<br>
|<br>
|(({p (1...9.3).max # cannot exclude non Integer end value (TypeError)}))<br>
|<br>
|I don't think it should do so.</p>
<p>OK, you don't think it should do so, then what do you think it should<br>
do? ... makes ranges excludes the end point. When the end point is<br>
floating point number, what should be the max value of the range, that<br>
should be less than (and not equals to) the end point?</p>
<p>I don't think ((end_obj-1).ceil) is not the best value for #max, since<br>
we don't define excluding end point by ((end_obj-1).ceil). yet, at<br>
least.</p>
<pre><code> matz.
</code></pre>
<p>=end</p> Ruby master - Bug #4577: (int...float).max should not raise an errorhttps://redmine.ruby-lang.org/issues/4577?journal_id=165042011-04-15T11:10:48Zyimutang (Joey Zhou)
<ul></ul><p>=begin<br>
Well, what I mean is ((<em>#max without block</em>)) and ((<em>#max {block}</em>)) should act the same way, maybe.</p>
<p>(1...6.3).max {|a,b| a <=> b} # 6</p>
<p>Why this one can iterate from 1 to 6, but not single #max ?</p>
<p>It seems there are two #max, one support #each, and another not.</p>
<p>I think this results in confusion.</p>
<p>Here:</p>
<p>p (1..6.3).last # 6.3, same as (1..6.3).end<br>
p (1..6.3).last(1) # [6]<br>
p (1...6.3).last(1) # [6], well... not [6.3]</p>
<p>two dots, or three dots, return the same array, with the element an int number.</p>
<p>thus #last(n) can return int number, although its end_obj is floating point number,<br>
I think (1...6.3).max returning int 6 is also OK. it can be a rule.</p>
<p>I think the methods' behaviour of Range class should be consistent, when the range contains floating point number.</p>
<p>Joey<br>
=end</p> Ruby master - Bug #4577: (int...float).max should not raise an errorhttps://redmine.ruby-lang.org/issues/4577?journal_id=165062011-04-15T12:19:02Zyimutang (Joey Zhou)
<ul></ul><p>=begin<br>
Ranges with numbers as begin_obj and end_obj can be summarized to four(..and...):</p>
<p>int..int # no problem<br>
float..float # no problem, float has no #succ, cannot iterate<br>
float..int # act as float..float, no problem, no #succ, no iteration<br>
int..float # I think more attention should be paid to this...</p>
<p>I suggest the feature here:</p>
<p>when int..float is used in #cover? #include? #===, there's no problem, just: begin_obj <=> obj and obj <=> end_obj</p>
<p>but when int..float(and int...float) is used in any method requiring iteration, the fractional part of float, may be dropped as scrap, if <em>needed</em>.</p>
<p>(1..5.3).to_a #=> [1,2,3,4,5]<br>
(1..5.0).to_a #=> [1,2,3,4,5]<br>
(1...5.3).to_a #=> [1,2,3,4,5]<br>
(1...5.0).to_a #=> [1,2,3,4]<br>
(1..5.3).last(1) #=> [5]<br>
(1...5.3).last(1) #=> [5]</p>
<p>the methods above are all OK, you can say there's a implicit rule: "0.3 is scrap, we dropped it"</p>
<p>but #last and #max:</p>
<p>(1..5.3).last #=> 5.3<br>
(1...5.3).last #=> 5.3<br>
(1..5.3).max #=> 5.3, well, same as #end<br>
hmm, #end, #last(no arg), #max(no block) all act the same, why should we need three methods to tell the end_obj?<br>
(1...5.3).max # ERROR!</p>
<p>(1..5.3).max {|a,b| a <=> b} # 5, fraction-scrap<br>
(1...5.3).max {|a,b| a <=> b} # 5 too</p>
<p>If the single #max follow "fraction-scrap" rule, I think it's better<br>
(1..5.3).max #=> 5<br>
(1...5.3).max #=> 5<br>
(1...5.0).max #=> 4<br>
=end</p> Ruby master - Bug #4577: (int...float).max should not raise an errorhttps://redmine.ruby-lang.org/issues/4577?journal_id=177782011-06-11T17:01:03Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul> Ruby master - Bug #4577: (int...float).max should not raise an errorhttps://redmine.ruby-lang.org/issues/4577?journal_id=280372012-07-14T15:05:56Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>After the discussion with core team members, I see no valid reason to make a change, except for vague feeling.<br>
So I reject it at the moment.</p>
<p>Matz.</p>