Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug#4655 #16

Closed
wants to merge 2 commits into from

3 participants

@tinco

This patch fixes support for scientific notation in complex numbers. Scientific notation numbers were incorrectly parsed as integers instead of floats.

Note that one commit fixes a bunch of related whitespace in complex.c. If this is not good that commit can be omitted without breaking the patch.

@nurse
Owner

This patch includes many whitespace changes, please remove it.
See also coding style http://redmine.ruby-lang.org/projects/ruby/wiki/DeveloperHowto

@tinco

Hey nurse, thanks for the comment, I have removed the whitespace commit.

@shyouhei
Owner

Seems mrkn has already pulled it. Thank you.

@shyouhei shyouhei closed this
@nurse nurse referenced this pull request from a commit
@nurse nurse * Merge Onigmo 5.13.4 f22cf2e566712cace60d17f84d63119d7c5764ee.
  [bug] fix problem with optimization of \z (Issue #16) [Bug #8210]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
536a327
@evanphx evanphx referenced this pull request from a commit
@nagachika nagachika merge revision(s) 40276: [Backport #8210]
	* Merge Onigmo 5.13.4 f22cf2e566712cace60d17f84d63119d7c5764ee.
	  [bug] fix problem with optimization of \z (Issue #16) [Bug #8210]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
8c43fc0
@sferik sferik referenced this pull request from a commit in sferik/ruby
@mrkn mrkn * complex.c (string_to_c_internal): support scientific notation.
  patched by Tinco Andringa. ruby/ruby#16
  [ruby-core:36046][Bug #4655]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ca927d6
@tenderlove tenderlove referenced this pull request from a commit in tenderlove/ruby
@mrkn mrkn * complex.c (string_to_c_internal): support scientific notation.
  patched by Tinco Andringa. ruby#16
  [ruby-core:36046][Bug #4655]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
bf6079c
@tenderlove tenderlove referenced this pull request from a commit in tenderlove/ruby
@nurse nurse * Merge Onigmo 5.13.4 f22cf2e566712cace60d17f84d63119d7c5764ee.
  [bug] fix problem with optimization of \z (Issue #16) [Bug #8210]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
cd0e7a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 2 deletions.
  1. +3 −2 complex.c
  2. +4 −0 test/ruby/test_complex.rb
View
5 complex.c
@@ -1498,6 +1498,7 @@ 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;
@@ -1518,7 +1519,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), '.'))
+ else if (strchr(RSTRING_PTR(sr), '.') || strchr(RSTRING_PTR(sr), 'e') || strchr(RSTRING_PTR(sr), 'E'))
r = f_to_f(sr);
else
r = f_to_i(sr);
@@ -1526,7 +1527,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), '.'))
+ else if (strchr(RSTRING_PTR(si), '.') || strchr(RSTRING_PTR(si), 'e') || strchr(RSTRING_PTR(si), 'E'))
i = f_to_f(si);
else
i = f_to_i(si);
View
4 test/ruby/test_complex.rb
@@ -704,6 +704,10 @@ def test_parse
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)
Something went wrong with that request. Please try again.