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

ruby-changes:7872

From: tadf <ko1@a...>
Date: Wed, 17 Sep 2008 07:04:36 +0900 (JST)
Subject: [ruby-changes:7872] Ruby:r19393 (trunk): * numeric.c: provides predicate real? instead of scalar?.

tadf	2008-09-17 07:04:19 +0900 (Wed, 17 Sep 2008)

  New Revision: 19393

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

  Log:
    * numeric.c: provides predicate real? instead of scalar?.
    
    * complex.c: follows the above change.
    
    * lib/cmath.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/lib/cmath.rb
    trunk/numeric.c
    trunk/test/ruby/test_complex.rb
    trunk/test/ruby/test_numeric.rb
    trunk/test/ruby/test_rational.rb

Index: complex.c
===================================================================
--- complex.c	(revision 19392)
+++ complex.c	(revision 19393)
@@ -24,7 +24,7 @@
 static ID id_Unify, id_abs, id_abs2, id_arg, id_cmp, id_conjugate,
     id_convert, id_denominator, id_divmod, id_equal_p, id_exact_p, id_expt,
     id_floor, id_hash, id_idiv, id_inspect, id_negate, id_new, id_new_bang,
-    id_numerator, id_polar, id_quo, id_scalar_p, id_to_f, id_to_i, id_to_r,
+    id_numerator, id_polar, id_quo, id_real_p, id_to_f, id_to_i, id_to_r,
     id_to_s, id_truncate;
 
 #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
@@ -168,10 +168,8 @@
 fun1(negate)
 fun1(numerator)
 fun1(polar)
-fun1(scalar_p)
+fun1(real_p)
 
-#define f_real_p f_scalar_p
-
 fun1(to_f)
 fun1(to_i)
 fun1(to_r)
@@ -1383,7 +1381,7 @@
     id_numerator = rb_intern("numerator");
     id_polar = rb_intern("polar");
     id_quo = rb_intern("quo");
-    id_scalar_p = rb_intern("scalar?");
+    id_real_p = rb_intern("real?");
     id_to_f = rb_intern("to_f");
     id_to_i = rb_intern("to_i");
     id_to_r = rb_intern("to_r");
@@ -1459,13 +1457,12 @@
     rb_define_method(rb_cComplex, "~", nucomp_conjugate, 0); /* gcc */
 #endif
 
-#if 0
     rb_define_method(rb_cComplex, "real?", nucomp_false, 0);
+#if 0
     rb_define_method(rb_cComplex, "complex?", nucomp_true, 0);
     rb_define_method(rb_cComplex, "exact?", nucomp_exact_p, 0);
     rb_define_method(rb_cComplex, "inexact?", nucomp_inexact_p, 0);
 #endif
-    rb_define_method(rb_cComplex, "scalar?", nucomp_false, 0);
 
     rb_define_method(rb_cComplex, "numerator", nucomp_numerator, 0);
     rb_define_method(rb_cComplex, "denominator", nucomp_denominator, 0);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19392)
+++ ChangeLog	(revision 19393)
@@ -1,3 +1,11 @@
+Wed Sep 17 06:58:31 2008  Tadayoshi Funaba  <tadf@d...>
+
+	* numeric.c: provides predicate real? instead of scalar?.
+
+	* complex.c: follows the above change.
+
+	* lib/cmath.c: ditto.
+
 Wed Sep 17 01:56:27 2008  Tanaka Akira  <akr@f...>
 
 	* test/ruby/test_io_m17n.rb: use __FILE__ instead of /dev/null.
Index: lib/cmath.rb
===================================================================
--- lib/cmath.rb	(revision 19392)
+++ lib/cmath.rb	(revision 19393)
@@ -25,7 +25,7 @@
   alias atanh! atanh
 
   def exp(z)
-    if z.scalar?
+    if z.real?
       exp!(z)
     else
       Complex(exp!(z.real) * cos!(z.image),
@@ -35,7 +35,7 @@
 
   def log(*args)
     z, b = args
-    if z.scalar? and z >= 0 and (b.nil? or b >= 0)
+    if z.real? and z >= 0 and (b.nil? or b >= 0)
       log!(*args)
     else
       r, theta = z.polar
@@ -48,7 +48,7 @@
   end
 
   def log10(z)
-    if z.scalar?
+    if z.real?
       log10!(z)
     else
       log(z) / log!(10)
@@ -56,7 +56,7 @@
   end
 
   def sqrt(z)
-    if z.scalar?
+    if z.real?
       if z >= 0
 	sqrt!(z)
       else
@@ -74,7 +74,7 @@
   end
 
   def sin(z)
-    if z.scalar?
+    if z.real?
       sin!(z)
     else
       Complex(sin!(z.real) * cosh!(z.image),
@@ -83,7 +83,7 @@
   end
 
   def cos(z)
-    if z.scalar?
+    if z.real?
       cos!(z)
     else
       Complex(cos!(z.real) * cosh!(z.image),
@@ -92,7 +92,7 @@
   end
 
   def tan(z)
-    if z.scalar?
+    if z.real?
       tan!(z)
     else
       sin(z)/cos(z)
@@ -100,7 +100,7 @@
   end
 
   def sinh(z)
-    if z.scalar?
+    if z.real?
       sinh!(z)
     else
       Complex(sinh!(z.real) * cos!(z.image),
@@ -109,7 +109,7 @@
   end
 
   def cosh(z)
-    if z.scalar?
+    if z.real?
       cosh!(z)
     else
       Complex(cosh!(z.real) * cos!(z.image),
@@ -118,7 +118,7 @@
   end
 
   def tanh(z)
-    if z.scalar?
+    if z.real?
       tanh!(z)
     else
       sinh(z) / cosh(z)
@@ -126,7 +126,7 @@
   end
 
   def asin(z)
-    if z.scalar? and z >= -1 and z <= 1
+    if z.real? and z >= -1 and z <= 1
       asin!(z)
     else
       -1.0.im * log(1.0.im * z + sqrt(1.0 - z * z))
@@ -134,7 +134,7 @@
   end
 
   def acos(z)
-    if z.scalar? and z >= -1 and z <= 1
+    if z.real? and z >= -1 and z <= 1
       acos!(z)
     else
       -1.0.im * log(z + 1.0.im * sqrt(1.0 - z * z))
@@ -142,7 +142,7 @@
   end
 
   def atan(z)
-    if z.scalar?
+    if z.real?
       atan!(z)
     else
       1.0.im * log((1.0.im + z) / (1.0.im - z)) / 2.0
@@ -150,7 +150,7 @@
   end
 
   def atan2(y,x)
-    if y.scalar? and x.scalar?
+    if y.real? and x.real?
       atan2!(y,x)
     else
       -1.0.im * log((x + 1.0.im * y) / sqrt(x * x + y * y))
@@ -158,7 +158,7 @@
   end
 
   def acosh(z)
-    if z.scalar? and z >= 1
+    if z.real? and z >= 1
       acosh!(z)
     else
       log(z + sqrt(z * z - 1.0))
@@ -166,7 +166,7 @@
   end
 
   def asinh(z)
-    if z.scalar?
+    if z.real?
       asinh!(z)
     else
       log(z + sqrt(1.0 + z * z))
@@ -174,7 +174,7 @@
   end
 
   def atanh(z)
-    if z.scalar? and z >= -1 and z <= 1
+    if z.real? and z >= -1 and z <= 1
       atanh!(z)
     else
       log((1.0 + z) / (1.0 - z)) / 2.0
Index: numeric.c
===================================================================
--- numeric.c	(revision 19392)
+++ numeric.c	(revision 19393)
@@ -385,14 +385,14 @@
 
 /*
  *  call-seq:
- *     num.scalar? -> true or false
+ *     num.real? -> true or false
  *
- *  Returns <code>true</code> if <i>num</i> is an <code>Scalar</code>
+ *  Returns <code>true</code> if <i>num</i> is a <code>Real</code>
  *  (i.e. non <code>Complex</code>).
  */
 
 static VALUE
-num_scalar_p(VALUE num)
+num_real_p(VALUE num)
 {
     return Qtrue;
 }
@@ -3145,7 +3145,7 @@
     rb_define_method(rb_cNumeric, "magnitude", num_abs, 0);
     rb_define_method(rb_cNumeric, "to_int", num_to_int, 0);
 
-    rb_define_method(rb_cNumeric, "scalar?", num_scalar_p, 0);
+    rb_define_method(rb_cNumeric, "real?", num_real_p, 0);
     rb_define_method(rb_cNumeric, "integer?", num_int_p, 0);
     rb_define_method(rb_cNumeric, "zero?", num_zero_p, 0);
     rb_define_method(rb_cNumeric, "nonzero?", num_nonzero_p, 0);
Index: test/ruby/test_numeric.rb
===================================================================
--- test/ruby/test_numeric.rb	(revision 19392)
+++ test/ruby/test_numeric.rb	(revision 19393)
@@ -72,8 +72,8 @@
     end
   end
 
-  def test_scalar_p
-    assert(Numeric.new.scalar?)
+  def test_real_p
+    assert(Numeric.new.real?)
   end
 
   def test_integer_p
Index: test/ruby/test_complex.rb
===================================================================
--- test/ruby/test_complex.rb	(revision 19392)
+++ test/ruby/test_complex.rb	(revision 19393)
@@ -243,7 +243,6 @@
     c = Complex(1)
 
     if defined?(Complex::Unify)
-      assert_equal(true, c.scalar?)
 =begin
       assert_equal(true, c.finite?)
       assert_equal(false, c.infinite?)
@@ -251,13 +250,14 @@
       assert_equal(true, c.integer?)
       assert_equal(false, c.float?)
       assert_equal(true, c.rational?)
+=end
       assert_equal(true, c.real?)
+=begin
       assert_equal(false, c.complex?)
       assert_equal(true, c.exact?)
       assert_equal(false, c.inexact?)
 =end
     else
-      assert_equal(false, c.scalar?)
 =begin
       assert_equal(true, c.finite?)
       assert_equal(false, c.infinite?)
@@ -265,7 +265,9 @@
       assert_equal(false, c.integer?)
       assert_equal(false, c.float?)
       assert_equal(false, c.rational?)
+=end
       assert_equal(false, c.real?)
+=begin
       assert_equal(true, c.complex?)
       assert_equal(true, c.exact?)
       assert_equal(false, c.inexact?)
@@ -882,8 +884,8 @@
   end
 
   def test_supp
-    assert_equal(true, 1.scalar?)
-    assert_equal(true, 1.1.scalar?)
+    assert_equal(true, 1.real?)
+    assert_equal(true, 1.1.real?)
 
     assert_equal(1, 1.real)
     assert_equal(0, 1.image)
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 19392)
+++ test/ruby/test_rational.rb	(revision 19393)
@@ -249,7 +249,6 @@
     c = Rational(1)
 
     if defined?(Rational::Unify)
-      assert_equal(true, c.scalar?)
 =begin
       assert_equal(true, c.finite?)
       assert_equal(false, c.infinite?)
@@ -257,13 +256,14 @@
       assert_equal(true, c.integer?)
       assert_equal(false, c.float?)
       assert_equal(true, c.rational?)
+=end
       assert_equal(true, c.real?)
+=begin
       assert_equal(false, c.complex?)
       assert_equal(true, c.exact?)
       assert_equal(false, c.inexact?)
 =end
     else
-      assert_equal(true, c.scalar?)
 =begin
       assert_equal(true, c.finite?)
       assert_equal(false, c.infinite?)
@@ -271,7 +271,9 @@
       assert_equal(false, c.integer?)
       assert_equal(false, c.float?)
       assert_equal(true, c.rational?)
+=end
       assert_equal(true, c.real?)
+=begin
       assert_equal(false, c.complex?)
       assert_equal(true, c.exact?)
       assert_equal(false, c.inexact?)
@@ -1054,8 +1056,8 @@
   end
 
   def test_supp
-    assert_equal(true, 1.scalar?)
-    assert_equal(true, 1.1.scalar?)
+    assert_equal(true, 1.real?)
+    assert_equal(true, 1.1.real?)
 
     assert_equal(1, 1.numerator)
     assert_equal(9, 9.numerator)

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

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