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

ruby-changes:12358

From: yugui <ko1@a...>
Date: Sun, 12 Jul 2009 23:46:52 +0900 (JST)
Subject: [ruby-changes:12358] Ruby:r24053 (ruby_1_9_1): merges r23946 from trunk into ruby_1_9_1.

yugui	2009-07-12 23:46:35 +0900 (Sun, 12 Jul 2009)

  New Revision: 24053

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

  Log:
    merges r23946 from trunk into ruby_1_9_1.
    --
    * complex.c: undef-ed shome methods.  [ruby-core:24110]
    * complex.c (Numeric#arg): NaN for NaN.  [ruby-core:24116]

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/complex.c
    branches/ruby_1_9_1/test/ruby/test_complex.rb
    branches/ruby_1_9_1/version.h

Index: ruby_1_9_1/complex.c
===================================================================
--- ruby_1_9_1/complex.c	(revision 24052)
+++ ruby_1_9_1/complex.c	(revision 24053)
@@ -1337,6 +1337,14 @@
 
 #define id_PI rb_intern("PI")
 
+/*
+ * call-seq:
+ *    num.arg    ->  0 or float
+ *    num.angle  ->  0 or float
+ *    num.phase  ->  0 or float
+ *
+ * Returns 0 if the value is positive, pi otherwise.
+ */
 static VALUE
 numeric_arg(VALUE self)
 {
@@ -1363,6 +1371,54 @@
     return self;
 }
 
+/*
+ * call-seq:
+ *    flo.arg    ->  0 or float
+ *    flo.angle  ->  0 or float
+ *    flo.phase  ->  0 or float
+ *
+ * Returns 0 if the value is positive, pi otherwise.
+ */
+static VALUE
+float_arg(VALUE self)
+{
+    if (isnan(RFLOAT_VALUE(self)))
+	return self;
+    return rb_call_super(0, 0);
+}
+
+/*
+ * A complex number can be represented as a paired real number with
+ * imaginary unit; a+bi.  Where a is real part, b is imaginary part
+ * and i is imaginary unit.  Real a equals complex a+0i
+ * mathematically.
+ *
+ * In ruby, you can create complex object with Complex, Complex::rect,
+ * Complex::polar or to_c method.
+ *
+ *    Complex(1)           #=> (1+0i)
+ *    Complex(2, 3)        #=> (2+3i)
+ *    Complex.polar(2, 3)  #=> (-1.9799849932008908+0.2822400161197344i)
+ *    3.to_c               #=> (3+0i)
+ *
+ * You can also create complex object from floating-point numbers or
+ * strings.
+ *
+ *    Complex(0.3)         #=> (0.3+0i)
+ *    Complex('0.3-0.5i')  #=> (0.3-0.5i)
+ *    Complex('2/3+3/4i')  #=> ((2/3)+(3/4)*i)
+ *    Complex('1@2')       #=> (-0.4161468365471424+0.9092974268256817i)
+ *
+ *    0.3.to_c             #=> (0.3+0i)
+ *    '0.3-0.5i'.to_c      #=> (0.3-0.5i)
+ *    '2/3+3/4i'.to_c      #=> ((2/3)+(3/4)*i)
+ *    '1@2'.to_c           #=> (-0.4161468365471424+0.9092974268256817i)
+ *
+ * A complex object is either an exact or an inexact number.
+ *
+ *    Complex(1, 1) / 2    #=> ((1/2)+(1/2)*i)
+ *    Complex(1, 1) / 2.0  #=> (0.5+0.5i)
+ */
 void
 Init_Complex(void)
 {
@@ -1413,16 +1469,19 @@
 
     rb_define_global_function("Complex", nucomp_f_complex, -1);
 
+    rb_undef_method(rb_cComplex, "%");
     rb_undef_method(rb_cComplex, "<");
     rb_undef_method(rb_cComplex, "<=");
     rb_undef_method(rb_cComplex, "<=>");
     rb_undef_method(rb_cComplex, ">");
     rb_undef_method(rb_cComplex, ">=");
     rb_undef_method(rb_cComplex, "between?");
+    rb_undef_method(rb_cComplex, "div");
     rb_undef_method(rb_cComplex, "divmod");
     rb_undef_method(rb_cComplex, "floor");
     rb_undef_method(rb_cComplex, "ceil");
     rb_undef_method(rb_cComplex, "modulo");
+    rb_undef_method(rb_cComplex, "remainder");
     rb_undef_method(rb_cComplex, "round");
     rb_undef_method(rb_cComplex, "step");
     rb_undef_method(rb_cComplex, "truncate");
@@ -1510,6 +1569,10 @@
     rb_define_method(rb_cNumeric, "conjugate", numeric_conj, 0);
     rb_define_method(rb_cNumeric, "conj", numeric_conj, 0);
 
+    rb_define_method(rb_cFloat, "arg", float_arg, 0);
+    rb_define_method(rb_cFloat, "angle", float_arg, 0);
+    rb_define_method(rb_cFloat, "phase", float_arg, 0);
+
     rb_define_const(rb_cComplex, "I",
 		    f_complex_new_bang2(rb_cComplex, ZERO, ONE));
 }
Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 24052)
+++ ruby_1_9_1/ChangeLog	(revision 24053)
@@ -1,3 +1,9 @@
+Fri Jul  3 19:48:40 2009  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c: undef-ed shome methods.  [ruby-core:24110]
+
+	* complex.c (Numeric#arg): NaN for NaN.  [ruby-core:24116]
+
 Thu Jul  2 07:53:44 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (parser_yylex): fixed wrong variable.
Index: ruby_1_9_1/version.h
===================================================================
--- ruby_1_9_1/version.h	(revision 24052)
+++ ruby_1_9_1/version.h	(revision 24053)
@@ -1,6 +1,6 @@
 #define RUBY_VERSION "1.9.1"
 #define RUBY_RELEASE_DATE "2009-07-12"
-#define RUBY_PATCHLEVEL 216
+#define RUBY_PATCHLEVEL 217
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_1/test/ruby/test_complex.rb
===================================================================
--- ruby_1_9_1/test/ruby/test_complex.rb	(revision 24052)
+++ ruby_1_9_1/test/ruby/test_complex.rb	(revision 24053)
@@ -519,7 +519,7 @@
       assert_instance_of(Fixnum, Complex(1,2) - Complex(1,2))
       assert_instance_of(Fixnum, Complex(1,2) * 0)
       assert_instance_of(Fixnum, Complex(1,2) / Complex(1,2))
-      assert_instance_of(Fixnum, Complex(1,2).div(Complex(1,2)))
+#      assert_instance_of(Fixnum, Complex(1,2).div(Complex(1,2)))
       assert_instance_of(Fixnum, Complex(1,2).quo(Complex(1,2)))
 #      assert_instance_of(Fixnum, Complex(1,2) ** 0) # mathn's bug
     end
@@ -779,17 +779,19 @@
 
   def test_respond
     c = Complex(1,1)
+    assert_equal(false, c.respond_to?(:%))
     assert_equal(false, c.respond_to?(:<))
     assert_equal(false, c.respond_to?(:<=))
     assert_equal(false, c.respond_to?(:<=>))
     assert_equal(false, c.respond_to?(:>))
     assert_equal(false, c.respond_to?(:>=))
     assert_equal(false, c.respond_to?(:between?))
-#    assert_equal(false, c.respond_to?(:div)) # ?
+    assert_equal(false, c.respond_to?(:div))
     assert_equal(false, c.respond_to?(:divmod))
     assert_equal(false, c.respond_to?(:floor))
     assert_equal(false, c.respond_to?(:ceil))
     assert_equal(false, c.respond_to?(:modulo))
+    assert_equal(false, c.respond_to?(:remainder))
     assert_equal(false, c.respond_to?(:round))
     assert_equal(false, c.respond_to?(:step))
     assert_equal(false, c.respond_to?(:tunrcate))

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

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