* complex.c (string_to_c_internal): support scientific notation.
patched by Tinco Andringa. https://github.com/ruby/ruby/pull/16 [ruby-core:36046][Bug #4655] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d3e5a29361
commit
ca927d60f4
@ -1,3 +1,9 @@
|
|||||||
|
Mon May 9 13:49:00 2011 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
|
* complex.c (string_to_c_internal): support scientific notation.
|
||||||
|
patched by Tinco Andringa. https://github.com/ruby/ruby/pull/16
|
||||||
|
[ruby-core:36046][Bug #4655]
|
||||||
|
|
||||||
Mon May 9 11:52:48 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
Mon May 9 11:52:48 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* numeric.c (int_ord): remove K&R style.
|
* numeric.c (int_ord): remove K&R style.
|
||||||
|
@ -1498,6 +1498,7 @@ string_to_c_internal(VALUE self)
|
|||||||
m = f_match(comp_pat2, s);
|
m = f_match(comp_pat2, s);
|
||||||
if (NIL_P(m))
|
if (NIL_P(m))
|
||||||
return rb_assoc_new(Qnil, self);
|
return rb_assoc_new(Qnil, self);
|
||||||
|
/* string is of form "x+yi" */
|
||||||
sr = f_aref(m, INT2FIX(1));
|
sr = f_aref(m, INT2FIX(1));
|
||||||
if (NIL_P(f_aref(m, INT2FIX(2))))
|
if (NIL_P(f_aref(m, INT2FIX(2))))
|
||||||
si = Qnil;
|
si = Qnil;
|
||||||
@ -1518,7 +1519,7 @@ string_to_c_internal(VALUE self)
|
|||||||
if (!NIL_P(sr)) {
|
if (!NIL_P(sr)) {
|
||||||
if (strchr(RSTRING_PTR(sr), '/'))
|
if (strchr(RSTRING_PTR(sr), '/'))
|
||||||
r = f_to_r(sr);
|
r = f_to_r(sr);
|
||||||
else if (strchr(RSTRING_PTR(sr), '.'))
|
else if (strchr(RSTRING_PTR(sr), '.') || strchr(RSTRING_PTR(sr), 'e') || strchr(RSTRING_PTR(sr), 'E'))
|
||||||
r = f_to_f(sr);
|
r = f_to_f(sr);
|
||||||
else
|
else
|
||||||
r = f_to_i(sr);
|
r = f_to_i(sr);
|
||||||
@ -1526,7 +1527,7 @@ string_to_c_internal(VALUE self)
|
|||||||
if (!NIL_P(si)) {
|
if (!NIL_P(si)) {
|
||||||
if (strchr(RSTRING_PTR(si), '/'))
|
if (strchr(RSTRING_PTR(si), '/'))
|
||||||
i = f_to_r(si);
|
i = f_to_r(si);
|
||||||
else if (strchr(RSTRING_PTR(si), '.'))
|
else if (strchr(RSTRING_PTR(si), '.') || strchr(RSTRING_PTR(si), 'e') || strchr(RSTRING_PTR(si), 'E'))
|
||||||
i = f_to_f(si);
|
i = f_to_f(si);
|
||||||
else
|
else
|
||||||
i = f_to_i(si);
|
i = f_to_i(si);
|
||||||
|
@ -704,6 +704,10 @@ class Complex_Test < Test::Unit::TestCase
|
|||||||
assert_equal(Complex(-0.33), '-0.33'.to_c)
|
assert_equal(Complex(-0.33), '-0.33'.to_c)
|
||||||
assert_equal(Complex(-0.33), '-0.3_3'.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,-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)
|
assert_equal(Complex.polar(10.5,10.5), '10.5@10.5'.to_c)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user