summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authorKenta Murata <mrkn@users.noreply.github.com>2020-10-26 18:43:30 +0900
committerGitHub <noreply@github.com>2020-10-26 18:43:30 +0900
commit69837229d74813c807e9d079aaee33aec2c7a4d0 (patch)
tree8610aa69e9a24fcb2815f018b8e79aa19d165bd7 /rational.c
parent52c630da004d9273e8e5fc91c6304e9eed902566 (diff)
rational.c: convert a numerator to rational before calling fdiv in Kernel.Rational() (#3702)
This makes `Rational(BigDecimal(1), 60) == Rational(1, 60)`. [Bug #16518]
Notes
Notes: Merged-By: mrkn <mrkn@ruby-lang.org>
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/rational.c b/rational.c
index 3176870..abf3331 100644
--- a/rational.c
+++ b/rational.c
@@ -2673,8 +2673,16 @@ nurat_convert(VALUE klass, VALUE numv, VALUE denv, int raise)
}
}
if ((k_numeric_p(a1) && k_numeric_p(a2)) &&
- (!f_integer_p(a1) || !f_integer_p(a2)))
+ (!f_integer_p(a1) || !f_integer_p(a2))) {
+ VALUE tmp = rb_protect(to_rational, a1, &state);
+ if (!state) {
+ a1 = tmp;
+ }
+ else {
+ rb_set_errinfo(Qnil);
+ }
return f_div(a1, a2);
+ }
}
a1 = nurat_int_value(a1);