[前][次][番号順一覧][スレッド一覧]

ruby-changes:44638

From: mrkn <ko1@a...>
Date: Fri, 11 Nov 2016 23:57:17 +0900 (JST)
Subject: [ruby-changes:44638] mrkn:r56711 (trunk): rational.c: optimize rational - {float, rational}

mrkn	2016-11-11 23:57:11 +0900 (Fri, 11 Nov 2016)

  New Revision: 56711

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56711

  Log:
    rational.c: optimize rational - {float,rational}
    
    * rational.c (f_addsub, nurat_sub): optimize rational - {float,rational}.
      Author: Tadashi Saito <tad.a.digger@g...>

  Modified files:
    trunk/rational.c
Index: rational.c
===================================================================
--- rational.c	(revision 56710)
+++ rational.c	(revision 56711)
@@ -693,7 +693,7 @@ f_addsub(VALUE self, VALUE anum, VALUE a https://github.com/ruby/ruby/blob/trunk/rational.c#L693
 	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 a https://github.com/ruby/ruby/blob/trunk/rational.c#L710
 	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) https://github.com/ruby/ruby/blob/trunk/rational.c#L787
 					     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)) {
 	{

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]