* 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
This commit is contained in:
parent
6bf7dd725b
commit
2e2fabc433
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
Wed Aug 10 19:30:00 2011 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Wed Aug 10 14:11:07 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Aug 10 14:11:07 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/mkmf.rb (init_mkmf): set $LIBRUBYARG regardless of shared
|
* lib/mkmf.rb (init_mkmf): set $LIBRUBYARG regardless of shared
|
||||||
|
17
complex.c
17
complex.c
@ -1339,7 +1339,8 @@ nucomp_to_f(VALUE self)
|
|||||||
* call-seq:
|
* call-seq:
|
||||||
* cmp.to_r -> rational
|
* 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
|
static VALUE
|
||||||
nucomp_to_r(VALUE self)
|
nucomp_to_r(VALUE self)
|
||||||
@ -1358,14 +1359,22 @@ nucomp_to_r(VALUE self)
|
|||||||
* call-seq:
|
* call-seq:
|
||||||
* cmp.rationalize([eps]) -> rational
|
* cmp.rationalize([eps]) -> rational
|
||||||
*
|
*
|
||||||
* Returns the value as a rational if possible. An optional argument
|
* If the imaginary part is exactly 0, returns the real part as a Rational,
|
||||||
* eps is always ignored.
|
* otherwise a RangeError is raised.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
nucomp_rationalize(int argc, VALUE *argv, VALUE self)
|
nucomp_rationalize(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
|
get_dat1(self);
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", NULL);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -13,6 +13,11 @@ class Complex_Test < Test::Unit::TestCase
|
|||||||
@unify = $".grep(/(?:^|#{seps})mathn(?:\.(?:rb|so))?/).size != 0
|
@unify = $".grep(/(?:^|#{seps})mathn(?:\.(?:rb|so))?/).size != 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_rationalize
|
||||||
|
assert_equal(1.quo(3), Complex(1/3.0, 0).rationalize, '[ruby-core:38885]')
|
||||||
|
assert_equal(1.quo(5), Complex(0.2, 0).rationalize, '[ruby-core:38885]')
|
||||||
|
end
|
||||||
|
|
||||||
def test_compsub
|
def test_compsub
|
||||||
c = ComplexSub.__send__(:convert, 1)
|
c = ComplexSub.__send__(:convert, 1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user