From bc4310718bc6bef6fd24fe273fe18c66387b8eb8 Mon Sep 17 00:00:00 2001 From: mrkn Date: Fri, 11 Nov 2016 16:17:56 +0000 Subject: [PATCH] rational.c: optimize Rational#/ * rational.c (f_muldiv, nurat_div): optimize Rational#/. Author: Tadashi Saito git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- rational.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rational.c b/rational.c index 44a720aebe..8a952f6b68 100644 --- a/rational.c +++ b/rational.c @@ -812,9 +812,9 @@ f_muldiv(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k) if (k == '/') { VALUE t; - if (f_negative_p(bnum)) { - anum = f_negate(anum); - bnum = f_negate(bnum); + if (INT_NEGATIVE_P(bnum)) { + anum = rb_int_uminus(anum); + bnum = rb_int_uminus(bnum); } t = bnum; bnum = bden; @@ -911,8 +911,8 @@ nurat_div(VALUE self, VALUE other) other, ONE, '/'); } } - else if (RB_TYPE_P(other, T_FLOAT)) - return rb_funcall(f_to_f(self), '/', 1, other); + else if (RB_FLOAT_TYPE_P(other)) + return DBL2NUM(nurat_to_double(self) / RFLOAT_VALUE(other)); else if (RB_TYPE_P(other, T_RATIONAL)) { if (f_zero_p(other)) rb_raise_zerodiv();