mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
268203c5fc
commit
d028d6984f
1 changed files with 12 additions and 12 deletions
24
rational.c
24
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue