From 4657a1ccd59b552f9990caa80024550dece14d85 Mon Sep 17 00:00:00 2001 From: mrkn Date: Fri, 11 Nov 2016 14:57:11 +0000 Subject: rational.c: optimize rational - {float,rational} * rational.c (f_addsub, nurat_sub): optimize rational - {float,rational}. Author: Tadashi Saito git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56711 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- rational.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'rational.c') diff --git a/rational.c b/rational.c index 909a7fc397..e4f737bbbe 100644 --- a/rational.c +++ b/rational.c @@ -693,7 +693,7 @@ f_addsub(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k) if (k == '+') c = rb_int_plus(a, b); else - c = f_sub(a, b); + c = rb_int_minus(a, b); b = rb_int_idiv(aden, 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 == '+') c = rb_int_plus(a, b); else - c = f_sub(a, b); + c = rb_int_minus(a, b); b = rb_int_idiv(aden, g); g = f_gcd(c, g); @@ -787,8 +787,8 @@ nurat_sub(VALUE self, VALUE other) dat->den); } } - else if (RB_TYPE_P(other, T_FLOAT)) { - return f_sub(f_to_f(self), other); + else if (RB_FLOAT_TYPE_P(other)) { + return DBL2NUM(RFLOAT_VALUE(nurat_to_f(self)) - RFLOAT_VALUE(other)); } else if (RB_TYPE_P(other, T_RATIONAL)) { { -- cgit v1.2.3