summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--range.c5
-rw-r--r--test/ruby/test_range.rb5
3 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index d1695c671a..4e49d55200 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Feb 5 12:50:47 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * 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@marc-andre.ca>
* enumerator.c: Use to_enum for Enumerable methods returning
diff --git a/range.c b/range.c
index 8b613ecdbf..dd94e8d747 100644
--- a/range.c
+++ b/range.c
@@ -20,7 +20,7 @@
#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)
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)
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,
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 1f370cfaee..0eb25480be 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -2,6 +2,7 @@ require 'test/unit'
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
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