aboutsummaryrefslogtreecommitdiffstats
path: root/rational.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-01 07:34:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-01 07:34:31 +0000
commit929e9713bbfd76140bced29c6f398904ae9d4a85 (patch)
treeabb04468573060b8a2ee3a5c56cbd717d0cfbb1a /rational.c
parent9563db5eb18eae0e59da22f000ef21ed7516c179 (diff)
downloadruby-929e9713bbfd76140bced29c6f398904ae9d4a85.tar.gz
complex.c: simplify division result
* complex.c (f_divide): canonicalize rationals to simplify integer complex results. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/rational.c b/rational.c
index d88f50f886..64fc10ce47 100644
--- a/rational.c
+++ b/rational.c
@@ -1991,6 +1991,15 @@ rb_numeric_quo(VALUE x, VALUE y)
return nurat_div(x, y);
}
+VALUE
+rb_rational_canonicalize(VALUE x)
+{
+ if (RB_TYPE_P(x, T_RATIONAL)) {
+ get_dat1(x);
+ if (f_one_p(dat->den)) return dat->num;
+ }
+ return x;
+}
/*
* call-seq: