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

ruby-changes:44639

From: mrkn <ko1@a...>
Date: Sat, 12 Nov 2016 00:11:07 +0900 (JST)
Subject: [ruby-changes:44639] mrkn:r56712 (trunk): rational.c: optimize rational * {float, huge rational, bignum}

mrkn	2016-11-12 00:11:04 +0900 (Sat, 12 Nov 2016)

  New Revision: 56712

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

  Log:
    rational.c: optimize rational * {float, huge rational, bignum}
    
    * rational.c (f_muldiv, nurat_mul):
      optimize rational * {float, huge rational, bignum}.
      Author: Tadashi Saito <tad.a.digger@g...>

  Modified files:
    trunk/rational.c
Index: rational.c
===================================================================
--- rational.c	(revision 56711)
+++ rational.c	(revision 56712)
@@ -837,8 +837,8 @@ f_muldiv(VALUE self, VALUE anum, VALUE a https://github.com/ruby/ruby/blob/trunk/rational.c#L837
 	VALUE g1 = f_gcd(anum, bden);
 	VALUE g2 = f_gcd(aden, bnum);
 
-	num = f_mul(f_idiv(anum, g1), f_idiv(bnum, g2));
-	den = f_mul(f_idiv(aden, g2), f_idiv(bden, g1));
+	num = rb_int_mul(rb_int_idiv(anum, g1), rb_int_idiv(bnum, g2));
+	den = rb_int_mul(rb_int_idiv(aden, g2), rb_int_idiv(bden, g1));
     }
     return f_rational_new_no_reduce2(CLASS_OF(self), num, den);
 }
@@ -867,8 +867,8 @@ nurat_mul(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/rational.c#L867
 			    other, ONE, '*');
 	}
     }
-    else if (RB_TYPE_P(other, T_FLOAT)) {
-	return f_mul(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/

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