rational.c: optimize rational - {float,rational}

* rational.c (f_addsub, nurat_sub): optimize rational - {float,rational}.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56711 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2016-11-11 14:57:11 +00:00
parent b848f3c7e1
commit 86ec117881

View File

@ -693,7 +693,7 @@ f_addsub(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
if (k == '+') if (k == '+')
c = rb_int_plus(a, b); c = rb_int_plus(a, b);
else else
c = f_sub(a, b); c = rb_int_minus(a, b);
b = rb_int_idiv(aden, g); b = rb_int_idiv(aden, g);
g = f_gcd(c, g); g = f_gcd(c, g);
@ -710,7 +710,7 @@ f_addsub(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
if (k == '+') if (k == '+')
c = rb_int_plus(a, b); c = rb_int_plus(a, b);
else else
c = f_sub(a, b); c = rb_int_minus(a, b);
b = rb_int_idiv(aden, g); b = rb_int_idiv(aden, g);
g = f_gcd(c, g); g = f_gcd(c, g);
@ -787,8 +787,8 @@ nurat_sub(VALUE self, VALUE other)
dat->den); dat->den);
} }
} }
else if (RB_TYPE_P(other, T_FLOAT)) { else if (RB_FLOAT_TYPE_P(other)) {
return f_sub(f_to_f(self), other); return DBL2NUM(RFLOAT_VALUE(nurat_to_f(self)) - RFLOAT_VALUE(other));
} }
else if (RB_TYPE_P(other, T_RATIONAL)) { else if (RB_TYPE_P(other, T_RATIONAL)) {
{ {