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

ruby-changes:44650

From: mrkn <ko1@a...>
Date: Sat, 12 Nov 2016 01:18:00 +0900 (JST)
Subject: [ruby-changes:44650] mrkn:r56723 (trunk): rational.c: optimize Rational#/

mrkn	2016-11-12 01:17:56 +0900 (Sat, 12 Nov 2016)

  New Revision: 56723

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

  Log:
    rational.c: optimize Rational#/
    
    * rational.c (f_muldiv, nurat_div): optimize Rational#/.
      Author: Tadashi Saito <tad.a.digger@g...>

  Modified files:
    trunk/rational.c
Index: rational.c
===================================================================
--- rational.c	(revision 56722)
+++ rational.c	(revision 56723)
@@ -812,9 +812,9 @@ f_muldiv(VALUE self, VALUE anum, VALUE a https://github.com/ruby/ruby/blob/trunk/rational.c#L812
     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) https://github.com/ruby/ruby/blob/trunk/rational.c#L911
 			    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();

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

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