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

ruby-changes:12199

From: tadf <ko1@a...>
Date: Sun, 28 Jun 2009 22:28:03 +0900 (JST)
Subject: [ruby-changes:12199] Ruby:r23883 (trunk): * complex.c (nucomp_expt): convert to a float when the given power

tadf	2009-06-28 22:27:48 +0900 (Sun, 28 Jun 2009)

  New Revision: 23883

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

  Log:
    * complex.c (nucomp_expt): convert to a float when the given power
      is a bignum.
    * rational.c (nurat_expt): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/rational.c

Index: complex.c
===================================================================
--- complex.c	(revision 23882)
+++ complex.c	(revision 23883)
@@ -227,6 +227,18 @@
 }
 
 inline static VALUE
+k_fixnum_p(VALUE x)
+{
+    return f_kind_of_p(x, rb_cFixnum);
+}
+
+inline static VALUE
+k_bignum_p(VALUE x)
+{
+    return f_kind_of_p(x, rb_cBignum);
+}
+
+inline static VALUE
 k_float_p(VALUE x)
 {
     return f_kind_of_p(x, rb_cFloat);
@@ -831,7 +843,7 @@
 		       f_mul(dat->imag, m_log_bang(r)));
 	return f_complex_polar(CLASS_OF(self), nr, ntheta);
     }
-    if (k_integer_p(other)) {
+    if (k_fixnum_p(other)) {
 	if (f_gt_p(other, ZERO)) {
 	    VALUE x, z, n;
 
@@ -862,9 +874,12 @@
     if (k_numeric_p(other) && f_real_p(other)) {
 	VALUE r, theta;
 
+	if (k_bignum_p(other))
+	    rb_warn("in a**b, b may be too big");
+
 	r = f_abs(self);
 	theta = f_arg(self);
-	return f_complex_polar(CLASS_OF(self), f_expt(r, other),
+	return f_complex_polar(CLASS_OF(self), rb_fexpt(r, other),
 			       f_mul(theta, other));
     }
     return rb_num_coerce_bin(self, other, id_expt);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23882)
+++ ChangeLog	(revision 23883)
@@ -1,3 +1,10 @@
+Sun Jun 28 22:25:07 2009  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c (nucomp_expt): convert to a float when the given power
+	  is a bignum.
+
+	* rational.c (nurat_expt): ditto.
+
 Sun Jun 28 21:16:48 2009  Tadayoshi Funaba  <tadf@d...>
 
 	* lib/cmath.rb (sqrt): fixed an issue [ruby-list:45852].
Index: rational.c
===================================================================
--- rational.c	(revision 23882)
+++ rational.c	(revision 23883)
@@ -902,7 +902,6 @@
 
     switch (TYPE(other)) {
       case T_FIXNUM:
-      case T_BIGNUM:
 	{
 	    VALUE num, den;
 
@@ -924,6 +923,8 @@
 	    }
 	    return f_rational_new2(CLASS_OF(self), num, den);
 	}
+      case T_BIGNUM:
+	rb_warn("in a**b, b may be too big");
       case T_FLOAT:
       case T_RATIONAL:
 	return rb_fexpt(f_to_f(self), other);

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

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