summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bignum.c2
-rw-r--r--numeric.c2
-rw-r--r--test/ruby/test_bignum.rb4
-rw-r--r--test/ruby/test_integer.rb15
4 files changed, 21 insertions, 2 deletions
diff --git a/bignum.c b/bignum.c
index 3207af9616..b650d83936 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6176,7 +6176,7 @@ rb_big_fdiv_double(VALUE x, VALUE y)
return big_fdiv_float(x, y);
}
else {
- return RFLOAT_VALUE(rb_num_coerce_bin(x, y, rb_intern("fdiv")));
+ return NUM2DBL(rb_num_coerce_bin(x, y, rb_intern("fdiv")));
}
return dx / dy;
}
diff --git a/numeric.c b/numeric.c
index 480ab7e0cb..597bfb54dd 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3629,7 +3629,7 @@ fix_fdiv_double(VALUE x, VALUE y)
return (double)FIX2LONG(x) / RFLOAT_VALUE(y);
}
else {
- return RFLOAT_VALUE(rb_num_coerce_bin(x, y, rb_intern("fdiv")));
+ return NUM2DBL(rb_num_coerce_bin(x, y, rb_intern("fdiv")));
}
}
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index e680d28735..3ead77766d 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -693,6 +693,10 @@ class TestBignum < Test::Unit::TestCase
o = Object.new
def o.coerce(x); [x, 2**100]; end
assert_equal((2**200).to_f, (2**300).fdiv(o))
+ o = Object.new
+ def o.coerce(x); [self, x]; end
+ def o.fdiv(x); 1; end
+ assert_equal(1.0, (2**300).fdiv(o))
end
def test_singleton_method
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index 9199bc0877..1b485760e3 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -510,4 +510,19 @@ class TestInteger < Test::Unit::TestCase
end
assert_empty(failures, bug13440)
end
+
+ def test_fdiv
+ assert_equal(1.0, 1.fdiv(1))
+ assert_equal(0.5, 1.fdiv(2))
+ end
+
+ def test_obj_fdiv
+ o = Object.new
+ def o.coerce(x); [x, 0.5]; end
+ assert_equal(2.0, 1.fdiv(o))
+ o = Object.new
+ def o.coerce(x); [self, x]; end
+ def o.fdiv(x); 1; end
+ assert_equal(1.0, 1.fdiv(o))
+ end
end