1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

rational.c: optimize rational + float.

* rational.c (rb_rational_plus): optimize rational + float.
  Author: Tadashi Saito <tad.a.digger@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2016-11-11 14:38:59 +00:00
parent 54bc0a446d
commit 70f5ad7c41

View file

@ -715,6 +715,7 @@ f_addsub(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
return f_rational_new_no_reduce2(CLASS_OF(self), num, den); return f_rational_new_no_reduce2(CLASS_OF(self), num, den);
} }
static VALUE nurat_to_f(VALUE self);
/* /*
* call-seq: * call-seq:
* rat + numeric -> numeric * rat + numeric -> numeric
@ -740,7 +741,7 @@ rb_rational_plus(VALUE self, VALUE other)
} }
} }
else if (RB_TYPE_P(other, T_FLOAT)) { else if (RB_TYPE_P(other, T_FLOAT)) {
return f_add(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)) {
{ {