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

ruby-changes:12257

From: tadf <ko1@a...>
Date: Fri, 3 Jul 2009 21:20:14 +0900 (JST)
Subject: [ruby-changes:12257] Ruby:r23947 (trunk): * rational.c: renamed equal_p to eqeq_p.

tadf	2009-07-03 21:19:54 +0900 (Fri, 03 Jul 2009)

  New Revision: 23947

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

  Log:
    * rational.c: renamed equal_p to eqeq_p.
    * complex.c: ditto.
    
    * complex.c (nucomp_equal_p): added.
      Complex(NaN).equal?(Complex(NaN)) should return true.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/rational.c
    trunk/test/ruby/test_complex.rb
    trunk/test/ruby/test_rational.rb

Index: complex.c
===================================================================
--- complex.c	(revision 23946)
+++ complex.c	(revision 23947)
@@ -18,9 +18,9 @@
 VALUE rb_cComplex;
 
 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_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;
+    id_denominator, id_divmod, id_eqeq_p, id_equal_p, id_expt, id_fdiv,
+    id_floor, 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)
 
@@ -177,6 +177,14 @@
     return rb_funcall(x, id_equal_p, 1, y);
 }
 
+inline static VALUE
+f_eqeq_p(VALUE x, VALUE y)
+{
+    if (FIXNUM_P(x) && FIXNUM_P(y))
+	return f_boolcast(FIX2LONG(x) == FIX2LONG(y));
+    return rb_funcall(x, id_eqeq_p, 1, y);
+}
+
 fun2(expt)
 fun2(fdiv)
 fun2(idiv)
@@ -197,7 +205,7 @@
 {
     if (FIXNUM_P(x))
 	return f_boolcast(FIX2LONG(x) == 0);
-    return rb_funcall(x, id_equal_p, 1, ZERO);
+    return rb_funcall(x, id_eqeq_p, 1, ZERO);
 }
 
 #define f_nonzero_p(x) (!f_zero_p(x))
@@ -207,7 +215,7 @@
 {
     if (FIXNUM_P(x))
 	return f_boolcast(FIX2LONG(x) == 1);
-    return rb_funcall(x, id_equal_p, 1, ONE);
+    return rb_funcall(x, id_eqeq_p, 1, ONE);
 }
 
 inline static VALUE
@@ -886,7 +894,7 @@
  * call-seq:
  *    cmp == object  ->  true or false
  *
- * Returns true if cmp equals object numerically.
+ * Returns true if cmp is same as object.
  */
 static VALUE
 nucomp_equal_p(VALUE self, VALUE other)
@@ -897,12 +905,30 @@
 	return f_boolcast(f_equal_p(adat->real, bdat->real) &&
 			  f_equal_p(adat->imag, bdat->imag));
     }
+    return Qfalse;
+}
+
+/*
+ * call-seq:
+ *    cmp == object  ->  true or false
+ *
+ * Returns true if cmp equals object numerically.
+ */
+static VALUE
+nucomp_eqeq_p(VALUE self, VALUE other)
+{
+    if (k_complex_p(other)) {
+	get_dat2(self, other);
+
+	return f_boolcast(f_eqeq_p(adat->real, bdat->real) &&
+			  f_eqeq_p(adat->imag, bdat->imag));
+    }
     if (k_numeric_p(other) && f_real_p(other)) {
 	get_dat1(self);
 
-	return f_boolcast(f_equal_p(dat->real, other) && f_zero_p(dat->imag));
+	return f_boolcast(f_eqeq_p(dat->real, other) && f_zero_p(dat->imag));
     }
-    return f_equal_p(other, self);
+    return f_eqeq_p(other, self);
 }
 
 /* :nodoc: */
@@ -1131,7 +1157,7 @@
 
 	return f_boolcast((CLASS_OF(adat->real) == CLASS_OF(bdat->real)) &&
 			  (CLASS_OF(adat->imag) == CLASS_OF(bdat->imag)) &&
-			  f_equal_p(self, other));
+			  f_eqeq_p(self, other));
 
     }
     return Qfalse;
@@ -1805,7 +1831,8 @@
     id_convert = rb_intern("convert");
     id_denominator = rb_intern("denominator");
     id_divmod = rb_intern("divmod");
-    id_equal_p = rb_intern("==");
+    id_equal_p = rb_intern("equal?");
+    id_eqeq_p = rb_intern("==");
     id_expt = rb_intern("**");
     id_fdiv = rb_intern("fdiv");
     id_floor = rb_intern("floor");
@@ -1874,7 +1901,8 @@
     rb_define_method(rb_cComplex, "fdiv", nucomp_fdiv, 1);
     rb_define_method(rb_cComplex, "**", nucomp_expt, 1);
 
-    rb_define_method(rb_cComplex, "==", nucomp_equal_p, 1);
+    rb_define_method(rb_cComplex, "equal?", nucomp_equal_p, 1);
+    rb_define_method(rb_cComplex, "==", nucomp_eqeq_p, 1);
     rb_define_method(rb_cComplex, "coerce", nucomp_coerce, 1);
 
     rb_define_method(rb_cComplex, "abs", nucomp_abs, 0);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 23946)
+++ ChangeLog	(revision 23947)
@@ -1,3 +1,12 @@
+Fri Jul  3 21:07:29 2009  Tadayoshi Funaba  <tadf@d...>
+
+	* rational.c: renamed equal_p to eqeq_p.
+
+	* complex.c: ditto.
+
+	* complex.c (nucomp_equal_p): added.
+	  Complex(NaN).equal?(Complex(NaN)) should return true.
+
 Fri Jul  3 19:48:40 2009  Tadayoshi Funaba  <tadf@d...>
 
 	* complex.c: undef-ed shome methods.  [ruby-core:24110]
Index: test/ruby/test_complex.rb
===================================================================
--- test/ruby/test_complex.rb	(revision 23946)
+++ test/ruby/test_complex.rb	(revision 23947)
@@ -489,6 +489,18 @@
   end
 
   def test_equal
+    unless @unify
+      assert_equal(true, Complex(1,0).equal?(Complex(1)))
+      assert_equal(false, Complex(1,0).equal?(Complex(1.0)))
+      if (0.0/0).nan?
+	nan = 0.0/0
+	assert_equal(true, Complex(nan).equal?(Complex(nan)))
+	assert_equal(false, Complex(nan).equal?(nan))
+      end
+    end
+  end
+
+  def test_eqeq
     assert(Complex(1,0) == Complex(1))
     assert(Complex(-1,0) == Complex(-1))
 
@@ -891,6 +903,13 @@
     assert_equal(0, 1.0.angle)
     assert_equal(0, 1.0.phase)
 
+    if (0.0/0).nan?
+      nan = 0.0/0
+      assert(nan.arg.equal?(nan))
+      assert(nan.angle.equal?(nan))
+      assert(nan.phase.equal?(nan))
+    end
+
     assert_equal(Math::PI, -1.arg)
     assert_equal(Math::PI, -1.angle)
     assert_equal(Math::PI, -1.phase)
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 23946)
+++ test/ruby/test_rational.rb	(revision 23947)
@@ -697,7 +697,7 @@
     assert_equal(nil, Rational(0) <=> 'foo')
   end
 
-  def test_equal
+  def test_eqeq
     assert(Rational(1,1) == Rational(1))
     assert(Rational(-1,1) == Rational(-1))
 
Index: rational.c
===================================================================
--- rational.c	(revision 23946)
+++ rational.c	(revision 23947)
@@ -22,7 +22,7 @@
 
 VALUE rb_cRational;
 
-static ID id_abs, id_cmp, id_convert, id_equal_p, id_expt, id_fdiv,
+static ID id_abs, id_cmp, id_convert, id_eqeq_p, id_expt, id_fdiv,
     id_floor, id_idiv, id_inspect, id_integer_p, id_negate, id_to_f,
     id_to_i, id_to_s, id_truncate;
 
@@ -142,11 +142,11 @@
 fun1(truncate)
 
 inline static VALUE
-f_equal_p(VALUE x, VALUE y)
+f_eqeq_p(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x) && FIXNUM_P(y))
 	return f_boolcast(FIX2LONG(x) == FIX2LONG(y));
-    return rb_funcall(x, id_equal_p, 1, y);
+    return rb_funcall(x, id_eqeq_p, 1, y);
 }
 
 fun2(expt)
@@ -168,7 +168,7 @@
 {
     if (FIXNUM_P(x))
 	return f_boolcast(FIX2LONG(x) == 0);
-    return rb_funcall(x, id_equal_p, 1, ZERO);
+    return rb_funcall(x, id_eqeq_p, 1, ZERO);
 }
 
 #define f_nonzero_p(x) (!f_zero_p(x))
@@ -178,7 +178,7 @@
 {
     if (FIXNUM_P(x))
 	return f_boolcast(FIX2LONG(x) == 1);
-    return rb_funcall(x, id_equal_p, 1, ONE);
+    return rb_funcall(x, id_eqeq_p, 1, ONE);
 }
 
 inline static VALUE
@@ -586,7 +586,7 @@
 f_imul(long x, long y)
 {
     VALUE r = f_imul_orig(x, y);
-    assert(f_equal_p(r, f_mul(LONG2NUM(x), LONG2NUM(y))));
+    assert(f_eqeq_p(r, f_mul(LONG2NUM(x), LONG2NUM(y))));
     return r;
 }
 #endif
@@ -1002,7 +1002,7 @@
  *    Rational('1/2') == '1/2'            #=> false
  */
 static VALUE
-nurat_equal_p(VALUE self, VALUE other)
+nurat_eqeq_p(VALUE self, VALUE other)
 {
     switch (TYPE(other)) {
       case T_FIXNUM:
@@ -1017,12 +1017,12 @@
 		return Qfalse;
 	    if (FIX2LONG(dat->den) != 1)
 		return Qfalse;
-	    if (f_equal_p(dat->num, other))
+	    if (f_eqeq_p(dat->num, other))
 		return Qtrue;
 	    return Qfalse;
 	}
       case T_FLOAT:
-	return f_equal_p(f_to_f(self), other);
+	return f_eqeq_p(f_to_f(self), other);
       case T_RATIONAL:
 	{
 	    get_dat2(self, other);
@@ -1030,11 +1030,11 @@
 	    if (f_zero_p(adat->num) && f_zero_p(bdat->num))
 		return Qtrue;
 
-	    return f_boolcast(f_equal_p(adat->num, bdat->num) &&
-			      f_equal_p(adat->den, bdat->den));
+	    return f_boolcast(f_eqeq_p(adat->num, bdat->num) &&
+			      f_eqeq_p(adat->den, bdat->den));
 	}
       default:
-	return f_equal_p(other, self);
+	return f_eqeq_p(other, self);
     }
 }
 
@@ -1988,7 +1988,7 @@
     id_abs = rb_intern("abs");
     id_cmp = rb_intern("<=>");
     id_convert = rb_intern("convert");
-    id_equal_p = rb_intern("==");
+    id_eqeq_p = rb_intern("==");
     id_expt = rb_intern("**");
     id_fdiv = rb_intern("fdiv");
     id_floor = rb_intern("floor");
@@ -2027,7 +2027,7 @@
     rb_define_method(rb_cRational, "**", nurat_expt, 1);
 
     rb_define_method(rb_cRational, "<=>", nurat_cmp, 1);
-    rb_define_method(rb_cRational, "==", nurat_equal_p, 1);
+    rb_define_method(rb_cRational, "==", nurat_eqeq_p, 1);
     rb_define_method(rb_cRational, "coerce", nurat_coerce, 1);
 
 #if 0 /* NUBY */

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

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