summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-11 13:35:22 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-11 13:35:22 +0000
commita704e21fcef27349b6a9826960d318025904a72d (patch)
tree555f86335a2f61e61c03a348d4b1aa7d0a0f47f4 /rational.c
parent8edc6f44871441c3df5ec0273f06852e7eccee79 (diff)
merge revision(s) 57232: [Backport #13084]
rational.c: fix for mathn * rational.c (read_num, read_rat_nos): dispatch by the type of numerator, for mathn. [ruby-core:78893] [Bug #13084] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@57843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/rational.c b/rational.c
index a78b347c08..2fd020429d 100644
--- a/rational.c
+++ b/rational.c
@@ -2365,11 +2365,22 @@ read_num(const char **s, int numsign, int strict,
exp = rb_int_uminus(exp);
}
- if (numsign == '-')
- *num = rb_rational_uminus(*num);
+ if (numsign == '-') {
+ if (RB_TYPE_P(*num, T_RATIONAL)) {
+ *num = rb_rational_uminus(*num);
+ }
+ else {
+ *num = rb_int_uminus(*num);
+ }
+ }
if (!NIL_P(exp)) {
VALUE l = f_expt10(exp);
- *num = nurat_mul(*num, l);
+ if (RB_TYPE_P(*num, T_RATIONAL)) {
+ *num = nurat_mul(*num, l);
+ }
+ else {
+ *num = rb_int_mul(*num, l);
+ }
}
return 1;
}
@@ -2395,8 +2406,14 @@ read_rat_nos(const char **s, int sign, int strict,
(*s)++;
if (!read_den(s, strict, &den))
return 0;
- if (!(FIXNUM_P(den) && FIX2LONG(den) == 1))
- *num = nurat_div(*num, den);
+ if (!(FIXNUM_P(den) && FIX2LONG(den) == 1)) {
+ if (RB_TYPE_P(*num, T_RATIONAL)) {
+ *num = nurat_div(*num, den);
+ }
+ else {
+ *num = rb_int_div(*num, den);
+ }
+ }
}
return 1;
}