summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-11 14:38:59 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-11 14:38:59 +0000
commit70f5ad7c41ba777fee820bbd5852e5a357a7ff75 (patch)
treee5b5c57a6d0f8434a32a5c8d626e17e244a86563
parent54bc0a446dd83c475c7ba540bccc1d9b3ad1e39a (diff)
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
-rw-r--r--rational.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/rational.c b/rational.c
index ebc6979a97d..3917541c13b 100644
--- a/rational.c
+++ b/rational.c
@@ -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);
}
+static VALUE nurat_to_f(VALUE self);
/*
* call-seq:
* rat + numeric -> numeric
@@ -740,7 +741,7 @@ rb_rational_plus(VALUE self, VALUE other)
}
}
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)) {
{