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

ruby-changes:37673

From: nobu <ko1@a...>
Date: Wed, 25 Feb 2015 23:16:18 +0900 (JST)
Subject: [ruby-changes:37673] nobu:r49754 (trunk): complex.c: specialize

nobu	2015-02-25 23:16:05 +0900 (Wed, 25 Feb 2015)

  New Revision: 49754

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

  Log:
    complex.c: specialize
    
    * complex.c (rb_nucomp_mul): specialize real numbers and purely
      imaginary numbers, and get rid of multiplication by zero.

  Modified files:
    trunk/complex.c
Index: complex.c
===================================================================
--- complex.c	(revision 49753)
+++ complex.c	(revision 49754)
@@ -756,20 +756,18 @@ rb_nucomp_mul(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/complex.c#L756
 {
     if (k_complex_p(other)) {
 	VALUE real, imag;
+	VALUE areal, aimag, breal, bimag;
 
 	get_dat2(self, other);
 
-	real = f_sub(f_mul(adat->real, bdat->real),
-		     f_mul(adat->imag, bdat->imag));
-	imag = f_add(f_mul(adat->real, bdat->imag),
-		     f_mul(adat->imag, bdat->real));
-
-	if ((RB_FLOAT_TYPE_P(real) && isnan(RFLOAT_VALUE(real))) ||
-	    (RB_FLOAT_TYPE_P(imag) && isnan(RFLOAT_VALUE(imag)))) {
-	    VALUE abs = f_mul(nucomp_abs(self), nucomp_abs(other));
-	    VALUE arg = f_add(nucomp_arg(self), nucomp_arg(other));
-	    return f_complex_polar(CLASS_OF(self), abs, arg);
-	}
+	if (f_zero_p(areal = adat->real)) areal = ZERO;
+	if (f_zero_p(aimag = adat->imag)) aimag = ZERO;
+	if (f_zero_p(breal = bdat->real)) breal = ZERO;
+	if (f_zero_p(bimag = bdat->imag)) bimag = ZERO;
+	real = (areal == ZERO || breal == ZERO) ? ZERO : f_mul(areal, breal);
+	if (aimag != ZERO && bimag != ZERO) real = f_sub(real, f_mul(aimag, bimag));
+	imag = (areal == ZERO || bimag == ZERO) ? ZERO : f_mul(areal, bimag);
+	if (aimag != ZERO && breal != ZERO) imag = f_add(imag, f_mul(aimag, breal));
 
 	return f_complex_new2(CLASS_OF(self), real, imag);
     }

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

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