1
0
Fork 0
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:
Nobuyoshi Nakada 2021-01-23 10:28:07 +09:00
parent 37258b64c7
commit a55eb9a2af
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 8 additions and 1 deletions

View file

@ -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);
}
/*

View file

@ -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