summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-09 11:31:26 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-09 11:31:26 +0000
commit6c81a8e44e3abe05ccffc7c26813308e7b347bcb (patch)
tree310c37ed62054a1cc4cbb66866db06b4bd32ca8f
parent140e1f0b15bc995b45caff0ac62af960d52b4441 (diff)
* complex.c (string_to_c_internal): a refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--complex.c5
-rw-r--r--test/ruby/test_complex.rb5
3 files changed, 7 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 03ecc43e07..08fa589f85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon May 9 20:29:44 2011 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * complex.c (string_to_c_internal): a refactoring.
+
Mon May 9 18:33:05 2011 NARUSE, Yui <naruse@ruby-lang.org>
* string.c: Improve documentation for String#start_with? and
diff --git a/complex.c b/complex.c
index c2d15ed2b6..0fcf63cf81 100644
--- a/complex.c
+++ b/complex.c
@@ -1498,7 +1498,6 @@ string_to_c_internal(VALUE self)
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 @@ string_to_c_internal(VALUE self)
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 @@ string_to_c_internal(VALUE self)
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);
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index 24083e1384..02f6eb30ca 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -704,10 +704,6 @@ class Complex_Test < Test::Unit::TestCase
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@10.5'.to_c)
@@ -1104,6 +1100,7 @@ class Complex_Test < Test::Unit::TestCase
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