summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-11 14:42:53 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-11 14:42:53 +0000
commitd028d6984fe23887348d2a63cb308d8b0761c84f (patch)
tree7ee688a925825b0e2825399c64ccbf3933f2360e /rational.c
parent268203c5fc69114a9541f737fe51bc2e77ae8d15 (diff)
rational.c: optimize rational + rational
* rational.c (f_addsub): optimize rational + rational. Author: Tadashi Saito <tad.a.digger@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/rational.c b/rational.c
index 0044024cbf..5be862bd54 100644
--- a/rational.c
+++ b/rational.c
@@ -691,32 +691,32 @@ f_addsub(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
VALUE c;
if (k == '+')
- c = f_add(a, b);
+ c = rb_int_plus(a, b);
else
c = f_sub(a, b);
- b = f_idiv(aden, g);
+ b = rb_int_idiv(aden, g);
g = f_gcd(c, g);
- num = f_idiv(c, g);
- a = f_idiv(bden, g);
- den = f_mul(a, b);
+ num = rb_int_idiv(c, g);
+ a = rb_int_idiv(bden, g);
+ den = rb_int_mul(a, b);
}
else {
VALUE g = f_gcd(aden, bden);
- VALUE a = f_mul(anum, f_idiv(bden, g));
- VALUE b = f_mul(bnum, f_idiv(aden, g));
+ VALUE a = rb_int_mul(anum, rb_int_idiv(bden, g));
+ VALUE b = rb_int_mul(bnum, rb_int_idiv(aden, g));
VALUE c;
if (k == '+')
- c = f_add(a, b);
+ c = rb_int_plus(a, b);
else
c = f_sub(a, b);
- b = f_idiv(aden, g);
+ b = rb_int_idiv(aden, g);
g = f_gcd(c, g);
- num = f_idiv(c, g);
- a = f_idiv(bden, g);
- den = f_mul(a, b);
+ num = rb_int_idiv(c, g);
+ a = rb_int_idiv(bden, g);
+ den = rb_int_mul(a, b);
}
return f_rational_new_no_reduce2(CLASS_OF(self), num, den);
}