mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make reciprocal properly of non-integral rational [Bug #17572]
This commit is contained in:
parent
37258b64c7
commit
a55eb9a2af
2 changed files with 8 additions and 1 deletions
|
@ -1868,7 +1868,7 @@ VALUE
|
|||
rb_rational_reciprocal(VALUE x)
|
||||
{
|
||||
get_dat1(x);
|
||||
return f_rational_new_no_reduce2(CLASS_OF(x), dat->den, dat->num);
|
||||
return nurat_convert(CLASS_OF(x), dat->den, dat->num, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -613,6 +613,13 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_nothing_raised(TypeError, '[Bug #5020] [ruby-dev:44088]') do
|
||||
Rational(1,2).coerce(Complex(1,1))
|
||||
end
|
||||
|
||||
assert_raise(ZeroDivisionError) do
|
||||
1 / 0r.coerce(0+0i)[0]
|
||||
end
|
||||
assert_raise(ZeroDivisionError) do
|
||||
1 / 0r.coerce(0.0+0i)[0]
|
||||
end
|
||||
end
|
||||
|
||||
class ObjectX
|
||||
|
|
Loading…
Reference in a new issue