ruby-changes:65009
From: Nobuyoshi <ko1@a...>
Date: Sat, 23 Jan 2021 10:32:01 +0900 (JST)
Subject: [ruby-changes:65009] a55eb9a2af (master): Make reciprocal properly of non-integral rational [Bug #17572]
https://git.ruby-lang.org/ruby.git/commit/?id=a55eb9a2af From a55eb9a2af7950d180d9d31ffde2bce66710f44f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 23 Jan 2021 10:28:07 +0900 Subject: 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(-) diff --git a/rational.c b/rational.c index 4a7df25..8548b3b 100644 --- a/rational.c +++ b/rational.c @@ -1868,7 +1868,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/rational.c#L1868 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); } /* diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 820dd30..fe9de64 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -613,6 +613,13 @@ class Rational_Test < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L613 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/