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

ruby-changes:12341

From: tadf <ko1@a...>
Date: Sun, 12 Jul 2009 21:09:38 +0900 (JST)
Subject: [ruby-changes:12341] Ruby:r24036 (trunk): * complex.c: use k_exact_{zero,one}_p macro.

tadf	2009-07-12 21:09:21 +0900 (Sun, 12 Jul 2009)

  New Revision: 24036

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

  Log:
    * complex.c: use k_exact_{zero,one}_p macro.
    * rational.c: ditto.

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

Index: complex.c
===================================================================
--- complex.c	(revision 24035)
+++ complex.c	(revision 24036)
@@ -261,6 +261,9 @@
 #define k_exact_p(x) (!k_float_p(x))
 #define k_inexact_p(x) k_float_p(x)
 
+#define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
+#define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
+
 #define get_dat1(x) \
     struct RComplex *dat;\
     dat = ((struct RComplex *)(x))
@@ -362,7 +365,7 @@
 #ifdef CANON
 #define CL_CANON
 #ifdef CL_CANON
-    if (f_zero_p(imag) && k_exact_p(imag) && canonicalization)
+    if (k_exact_zero_p(imag) && canonicalization)
 	return real;
 #else
     if (f_zero_p(imag) && canonicalization)
@@ -758,10 +761,6 @@
 static VALUE
 nucomp_div(VALUE self, VALUE other)
 {
-#if 0 /* too much cost */
-    if (f_zero_p(other) && k_exact_p(self) && k_exact_p(other))
-	rb_raise_zerodiv();
-#endif
     return f_divide(self, other, f_quo, id_quo);
 }
 
@@ -832,7 +831,7 @@
 static VALUE
 nucomp_expt(VALUE self, VALUE other)
 {
-    if (f_zero_p(other) && k_exact_p(other))
+    if (k_exact_zero_p(other))
 	return f_complex_new_bang1(CLASS_OF(self), ONE);
 
     if (k_rational_p(other) && f_one_p(f_denominator(other)))
@@ -841,7 +840,7 @@
     if (k_complex_p(other)) {
 	get_dat1(other);
 
-	if (k_exact_p(dat->imag) && f_zero_p(dat->imag))
+	if (k_exact_zero_p(dat->imag))
 	    other = dat->real; /* c14n */
     }
 
@@ -1062,7 +1061,7 @@
 nucomp_exact_p(VALUE self)
 {
     get_dat1(self);
-    return f_boolcast(f_exact_p(dat->real) && f_exact_p(dat->imag));
+    return f_boolcast(k_exact_p(dat->real) && k_exact_p(dat->imag));
 }
 
 /* :nodoc: */
@@ -1625,7 +1624,7 @@
 	{
 	    get_dat1(a1);
 
-	    if (k_exact_p(dat->imag) && f_zero_p(dat->imag))
+	    if (k_exact_zero_p(dat->imag))
 		a1 = dat->real;
 	}
     }
@@ -1635,14 +1634,14 @@
 	{
 	    get_dat1(a2);
 
-	    if (k_exact_p(dat->imag) && f_zero_p(dat->imag))
+	    if (k_exact_zero_p(dat->imag))
 		a2 = dat->real;
 	}
     }
 
     switch (TYPE(a1)) {
       case T_COMPLEX:
-	if (argc == 1 || (k_exact_p(a2) && f_zero_p(a2)))
+	if (argc == 1 || (k_exact_zero_p(a2)))
 	    return a1;
     }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24035)
+++ ChangeLog	(revision 24036)
@@ -1,3 +1,9 @@
+Sun Jul 12 21:07:46 2009  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c: use k_exact_{zero,one}_p macro.
+
+	* rational.c: ditto.
+
 Sun Jul 12 20:42:58 2009  Tadayoshi Funaba  <tadf@d...>
 
 	* numeric.c (fix_divide): added an entry to rational.
Index: rational.c
===================================================================
--- rational.c	(revision 24035)
+++ rational.c	(revision 24036)
@@ -214,6 +214,9 @@
 #define k_exact_p(x) (!k_float_p(x))
 #define k_inexact_p(x) k_float_p(x)
 
+#define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
+#define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
+
 #ifndef NDEBUG
 #define f_gcd f_gcd_orig
 #endif
@@ -892,7 +895,7 @@
 static VALUE
 nurat_expt(VALUE self, VALUE other)
 {
-    if (k_exact_p(other) && f_zero_p(other))
+    if (k_exact_zero_p(other))
 	return f_rational_new_bang1(CLASS_OF(self), ONE);
 
     if (k_rational_p(other)) {
@@ -1051,7 +1054,7 @@
       case T_RATIONAL:
 	return rb_assoc_new(other, self);
       case T_COMPLEX:
-	if (k_exact_p(RCOMPLEX(other)->imag) && f_zero_p(RCOMPLEX(other)->imag))
+	if (k_exact_zero_p(RCOMPLEX(other)->imag))
 	    return rb_assoc_new(f_rational_new_bang1
 				(CLASS_OF(self), RCOMPLEX(other)->real), self);
     }
@@ -1882,13 +1885,13 @@
 
     switch (TYPE(a1)) {
       case T_COMPLEX:
-	if (k_exact_p(RCOMPLEX(a1)->imag) && f_zero_p(RCOMPLEX(a1)->imag))
+	if (k_exact_zero_p(RCOMPLEX(a1)->imag))
 	    a1 = RCOMPLEX(a1)->real;
     }
 
     switch (TYPE(a2)) {
       case T_COMPLEX:
-	if (k_exact_p(RCOMPLEX(a2)->imag) && f_zero_p(RCOMPLEX(a2)->imag))
+	if (k_exact_zero_p(RCOMPLEX(a2)->imag))
 	    a2 = RCOMPLEX(a2)->real;
     }
 
@@ -1923,7 +1926,7 @@
 
     switch (TYPE(a1)) {
       case T_RATIONAL:
-	if (argc == 1 || (k_exact_p(a2) && f_one_p(a2)))
+	if (argc == 1 || (k_exact_one_p(a2)))
 	    return a1;
     }
 

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

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