Project

General

Profile

Bug #5178

Complex#rationalize should rationalize

Added by marcandre (Marc-Andre Lafortune) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
r32354
Backport:
[ruby-core:38885]

Description

Complex#rationalize currently calls to_r on the real part instead of rationalize:

f = 1/3.0
c = Complex(f)
c.to_r == f.to_r # => true
c.rationalize == f.rationalize # => false

Should I not commit this to 1.9.3 too?

diff --git a/complex.c b/complex.c
index 78f0902..1b76074 100644
--- a/complex.c
+++ b/complex.c
@@ -1335,7 +1335,8 @@ nucomp_to_f(VALUE self)

  • call-seq:
  • cmp.to_r -> rational *
    • * Returns the value as a rational if possible.
    • * If the imaginary part is exactly 0, returns the real part as a Rational,
    • * otherwise a RangeError is raised. */ static VALUE nucomp_to_r(VALUE self) @@ -1354,14 +1355,22 @@ nucomp_to_r(VALUE self)
  • call-seq:
  • cmp.rationalize([eps]) -> rational *
    • * Returns the value as a rational if possible. An optional argument
    • * eps is always ignored.
    • * If the imaginary part is exactly 0, returns the real part as a Rational,
    • * otherwise a RangeError is raised. */ static VALUE nucomp_rationalize(int argc, VALUE *argv, VALUE self) {
    • get_dat1(self); + rb_scan_args(argc, argv, "01", NULL);
    • return nucomp_to_r(self); +
    • if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
    • VALUE s = f_to_s(self);
    • rb_raise(rb_eRangeError, "can't convert %s into Rational",
    • StringValuePtr(s));
    • }
    • return rb_funcall(dat->real, rb_intern("rationalize"), argc, argv); }

Associated revisions

Revision 2e2fabc4
Added by mrkn (Kenta Murata) over 8 years ago

  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 32903
Added by mrkn (Kenta Murata) over 8 years ago

  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

Revision 32903
Added by mrkn (Kenta Murata) over 8 years ago

  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

Revision 32903
Added by mrkn (Kenta Murata) over 8 years ago

  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

Revision 32903
Added by mrkn (Kenta Murata) over 8 years ago

  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

Revision 32903
Added by mrkn (Kenta Murata) over 8 years ago

  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

Revision 32903
Added by mrkn (Kenta Murata) over 8 years ago

  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

Revision d72d87cd
Added by mrkn (Kenta Murata) over 8 years ago

Merge the commit r32903:
* complex.c (nucomp_rationalize): calls rationalize of real part if
imaginary part is exactly zero. The patch is made by Marc-Andre
Lafortune. fixes [Bug #5178] [ruby-core:38885]
* test/ruby/test_complex.rb (test_rationalize): add a test for the
above change.
* complex.c (nucomp_to_r): fix RDoc comment. The patch is made by
Marc-Andre Lafortune.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

#1

Updated by mrkn (Kenta Murata) over 8 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32903.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • complex.c (nucomp_rationalize): calls rationalize of real part if imaginary part is exactly zero. The patch is made by Marc-Andre Lafortune. fixes [Bug #5178] [ruby-core:38885]
  • test/ruby/test_complex.rb (test_rationalize): add a test for the above change.
  • complex.c (nucomp_to_r): fix RDoc comment. The patch is made by Marc-Andre Lafortune.

Also available in: Atom PDF