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

ruby-changes:19454

From: tadf <ko1@a...>
Date: Mon, 9 May 2011 20:31:34 +0900 (JST)
Subject: [ruby-changes:19454] Ruby:r31494 (trunk): * complex.c (string_to_c_internal): a refactoring.

tadf	2011-05-09 20:31:26 +0900 (Mon, 09 May 2011)

  New Revision: 31494

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

  Log:
    * complex.c (string_to_c_internal): a refactoring.

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

Index: complex.c
===================================================================
--- complex.c	(revision 31493)
+++ complex.c	(revision 31494)
@@ -1498,7 +1498,6 @@
 	    m = f_match(comp_pat2, s);
 	    if (NIL_P(m))
 		return rb_assoc_new(Qnil, self);
-	    /* string is of form "x+yi" */
 	    sr = f_aref(m, INT2FIX(1));
 	    if (NIL_P(f_aref(m, INT2FIX(2))))
 		si = Qnil;
@@ -1519,7 +1518,7 @@
 	if (!NIL_P(sr)) {
 	    if (strchr(RSTRING_PTR(sr), '/'))
 		r = f_to_r(sr);
-	    else if (strchr(RSTRING_PTR(sr), '.') || strchr(RSTRING_PTR(sr), 'e') || strchr(RSTRING_PTR(sr), 'E'))
+	    else if (strpbrk(RSTRING_PTR(sr), ".eE"))
 		r = f_to_f(sr);
 	    else
 		r = f_to_i(sr);
@@ -1527,7 +1526,7 @@
 	if (!NIL_P(si)) {
 	    if (strchr(RSTRING_PTR(si), '/'))
 		i = f_to_r(si);
-	    else if (strchr(RSTRING_PTR(si), '.') || strchr(RSTRING_PTR(si), 'e') || strchr(RSTRING_PTR(si), 'E'))
+	    else if (strpbrk(RSTRING_PTR(si), ".eE"))
 		i = f_to_f(si);
 	    else
 		i = f_to_i(si);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31493)
+++ ChangeLog	(revision 31494)
@@ -1,3 +1,7 @@
+Mon May  9 20:29:44 2011  Tadayoshi Funaba  <tadf@d...>
+
+	* complex.c (string_to_c_internal): a refactoring.
+
 Mon May  9 18:33:05 2011  NARUSE, Yui  <naruse@r...>
 
 	* string.c: Improve documentation for String#start_with? and
Index: test/ruby/test_complex.rb
===================================================================
--- test/ruby/test_complex.rb	(revision 31493)
+++ test/ruby/test_complex.rb	(revision 31494)
@@ -704,10 +704,6 @@
     assert_equal(Complex(-0.33), '-0.33'.to_c)
     assert_equal(Complex(-0.33), '-0.3_3'.to_c)
 
-    assert_equal(Complex(2, 2e4), '2+2e4i'.to_c)
-    assert_equal(Complex(2e3, 2), '2e3+2i'.to_c)
-    assert_equal(Complex(2e3, 2e4), '2e3+2e4i'.to_c)
-
     assert_equal(Complex.polar(10,10), '10@10'.to_c)
     assert_equal(Complex.polar(-10,-10), '-10@-10'.to_c)
     assert_equal(Complex.polar(10.5,10.5), '10.5@1...'.to_c)
@@ -1104,6 +1100,7 @@
     end
     assert_equal('-1.0-0.0i', Complex(-1.0, -0.0).to_s)
     assert_in_delta(Math::PI, Complex(-0.0).arg, 0.001)
+    assert_equal(Complex(2e3, 2e4), '2e3+2e4i'.to_c)
   end
 
   def test_known_bug

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

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