diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-10 10:40:21 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-10 10:40:21 +0000 |
commit | d72d87cd2de6e180d39359b31b4d96dbab61221f (patch) | |
tree | 64c3d28daf4be9ef3ce0683362fed6d0a9c1b5f4 /complex.c | |
parent | 6a1bb3514f50c917f8030c09b0419763ac280a81 (diff) |
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
Diffstat (limited to 'complex.c')
-rw-r--r-- | complex.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -1339,7 +1339,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) @@ -1358,14 +1359,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); } /* |