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

ruby-changes:12209

From: tadf <ko1@a...>
Date: Mon, 29 Jun 2009 21:03:40 +0900 (JST)
Subject: [ruby-changes:12209] Ruby:r23894 (trunk): * complex.c (nucomp_expt): checks exactness.

tadf	2009-06-29 21:03:25 +0900 (Mon, 29 Jun 2009)

  New Revision: 23894

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

  Log:
    * complex.c (nucomp_expt): checks exactness.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c

Index: complex.c
===================================================================
--- complex.c	(revision 23893)
+++ complex.c	(revision 23894)
@@ -19,8 +19,8 @@
 
 static ID id_abs, id_abs2, id_arg, id_cmp, id_conj, id_convert,
     id_denominator, id_divmod, id_equal_p, id_expt, id_fdiv, id_floor,
-    id_idiv, id_inspect, id_negate, id_numerator, id_quo, id_real_p,
-    id_to_f, id_to_i, id_to_r, id_to_s;
+    id_idiv, id_imag, id_inspect, id_negate, id_numerator, id_quo,
+    id_real, id_real_p, id_to_f, id_to_i, id_to_r, id_to_s;
 
 #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
 
@@ -155,9 +155,11 @@
 fun1(conj)
 fun1(denominator)
 fun1(floor)
+fun1(imag)
 fun1(inspect)
 fun1(negate)
 fun1(numerator)
+fun1(real)
 fun1(real_p)
 
 fun1(to_f)
@@ -778,16 +780,14 @@
 static VALUE
 m_exp(VALUE x)
 {
-    VALUE ere;
+    VALUE ere, im;
 
     if (f_real_p(x))
 	return m_exp_bang(x);
-    {
-	get_dat1(x);
-	ere = m_exp_bang(dat->real);
-	return rb_complex_new2(f_mul(ere, m_cos_bang(dat->imag)),
-			       f_mul(ere, m_sin_bang(dat->imag)));
-    }
+    ere = m_exp_bang(f_real(x));
+    im = f_imag(x);
+    return rb_complex_new2(f_mul(ere, m_cos_bang(im)),
+			   f_mul(ere, m_sin_bang(im)));
 }
 
 VALUE
@@ -821,14 +821,14 @@
     if (k_complex_p(other)) {
 	get_dat1(other);
 
-	if (f_zero_p(dat->imag))
+	if (k_exact_p(dat->imag) && f_zero_p(dat->imag))
 	    other = dat->real; /* c14n */
     }
 
     {
 	get_dat1(self);
 
-	if (f_zero_p(dat->imag) && f_real_p(other))
+	if (k_exact_p(dat->imag) && f_zero_p(dat->imag) && f_real_p(other))
 	    return f_complex_new1(CLASS_OF(self),
 				  rb_fexpt(dat->real, other)); /* c14n */
     }
@@ -1801,10 +1801,12 @@
     id_fdiv = rb_intern("fdiv");
     id_floor = rb_intern("floor");
     id_idiv = rb_intern("div");
+    id_imag = rb_intern("imag");
     id_inspect = rb_intern("inspect");
     id_negate = rb_intern("-@");
     id_numerator = rb_intern("numerator");
     id_quo = rb_intern("quo");
+    id_real = rb_intern("real");
     id_real_p = rb_intern("real?");
     id_to_f = rb_intern("to_f");
     id_to_i = rb_intern("to_i");
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23893)
+++ ChangeLog	(revision 23894)
@@ -1,3 +1,7 @@
+Mon Jun 29 21:01:31 2009  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c (nucomp_expt): checks exactness.
+
 Mon Jun 29 20:29:11 2009  Tadayoshi Funaba  <tadf@d...>
 
 	* rational.c (float_to_r): always returns rational.

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

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