[前][次][番号順一覧][スレッド一覧]

ruby-changes:27007

From: marcandre <ko1@a...>
Date: Tue, 5 Feb 2013 12:51:21 +0900 (JST)
Subject: [ruby-changes:27007] marcandRe: r39059 (trunk): * range.c: Use div instead of / for bsearch

marcandre	2013-02-05 12:51:09 +0900 (Tue, 05 Feb 2013)

  New Revision: 39059

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39059

  Log:
    * range.c: Use div instead of / for bsearch
    
    * test/ruby/test_range.rb: Test showing bug when requiring mathn

  Modified files:
    trunk/ChangeLog
    trunk/range.c
    trunk/test/ruby/test_range.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39058)
+++ ChangeLog	(revision 39059)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Feb  5 12:50:47 2013  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* range.c: Use div instead of / for bsearch
+
+	* test/ruby/test_range.rb: Test showing bug when requiring mathn
+
 Tue Feb  5 12:48:38 2013  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* enumerator.c: Use to_enum for Enumerable methods returning
Index: range.c
===================================================================
--- range.c	(revision 39058)
+++ range.c	(revision 39059)
@@ -20,7 +20,7 @@ https://github.com/ruby/ruby/blob/trunk/range.c#L20
 #include <math.h>
 
 VALUE rb_cRange;
-static ID id_cmp, id_succ, id_beg, id_end, id_excl, id_integer_p;
+static ID id_cmp, id_succ, id_beg, id_end, id_excl, id_integer_p, id_div;
 
 #define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
 #define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
@@ -656,7 +656,7 @@ range_bsearch(VALUE range) https://github.com/ruby/ruby/blob/trunk/range.c#L656
 	org_high = high;
 
 	while (rb_cmpint(rb_funcall(low, id_cmp, 1, high), low, high) < 0) {
-	    mid = rb_funcall(rb_funcall(high, '+', 1, low), '/', 1, INT2FIX(2));
+	    mid = rb_funcall(rb_funcall(high, '+', 1, low), id_div, 1, INT2FIX(2));
 	    BSEARCH_CHECK(mid);
 	    if (smaller) {
 		high = mid;
@@ -1311,6 +1311,7 @@ Init_Range(void) https://github.com/ruby/ruby/blob/trunk/range.c#L1311
     id_end = rb_intern("end");
     id_excl = rb_intern("excl");
     id_integer_p = rb_intern("integer?");
+    id_div = rb_intern("div");
 
     rb_cRange = rb_struct_define_without_accessor(
         "Range", rb_cObject, range_alloc,
Index: test/ruby/test_range.rb
===================================================================
--- test/ruby/test_range.rb	(revision 39058)
+++ test/ruby/test_range.rb	(revision 39059)
@@ -2,6 +2,7 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L2
 require 'delegate'
 require 'timeout'
 require 'bigdecimal'
+require_relative 'envutil'
 
 class TestRange < Test::Unit::TestCase
   def test_range_string
@@ -535,4 +536,8 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L536
 
     assert_raise(TypeError) { ("a".."z").bsearch {} }
   end
+
+  def test_bsearch_with_mathn
+    assert_in_out_err ['-r', 'mathn', '-e', 'puts (1..(1<<100)).bsearch{|x| raise "#{x} should be integer" unless x.integer?; x >= 42}'], "", ["42"], [], '[ruby-core:25740]'
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]