summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-11 14:57:11 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-11 14:57:11 +0000
commit86ec1178810b3a2d9a9a015108b5a2b42651d1fa (patch)
treec9c641b353f67359bbbf4c0ca9071ba39ce72d64
parentb848f3c7e1f1d6ded0ccc1e045b58f5cdccfb9b5 (diff)
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
-rw-r--r--rational.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/rational.c b/rational.c
index 909a7fc3976..e4f737bbbed 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)) {
{