1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) a55eb9a2af: [Backport #17572]

Make reciprocal properly of non-integral rational [Bug #17572]

	---
	 rational.c                 | 2 +-
	 test/ruby/test_rational.rb | 7 +++++++
	 2 files changed, 8 insertions(+), 1 deletion(-)
This commit is contained in:
nagachika 2021-02-11 13:34:05 +09:00
parent 9cc8b2a672
commit 4b6df7f735
3 changed files with 9 additions and 2 deletions

View file

@ -1875,7 +1875,7 @@ VALUE
rb_rational_reciprocal(VALUE x) rb_rational_reciprocal(VALUE x)
{ {
get_dat1(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

@ -598,6 +598,13 @@ class Rational_Test < Test::Unit::TestCase
assert_nothing_raised(TypeError, '[Bug #5020] [ruby-dev:44088]') do assert_nothing_raised(TypeError, '[Bug #5020] [ruby-dev:44088]') do
Rational(1,2).coerce(Complex(1,1)) Rational(1,2).coerce(Complex(1,1))
end 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 end
class ObjectX class ObjectX

View file

@ -2,7 +2,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 3 #define RUBY_VERSION_TEENY 3
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 152 #define RUBY_PATCHLEVEL 153
#define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 2 #define RUBY_RELEASE_MONTH 2