From b30d203fed8c29fd05d010631ca8e4750ce34849 Mon Sep 17 00:00:00 2001 From: mrkn Date: Wed, 17 Aug 2011 01:24:22 +0000 Subject: * rational.c (nurat_coerce): Rational#coerce should converts itself into Complex if the argument is a Complex with non-zero imaginary part. [Bug #5020] [ruby-dev:44088] * test/ruby/test_rational.rb (test_coerce): test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 +++++++++++++++ rational.c | 2 ++ test/ruby/test_rational.rb | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0ea864d0b1..073126fdfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Aug 17 10:16:00 2011 Kenta Murata + + * rational.c (nurat_coerce): Rational#coerce should converts itself + into Complex if the argument is a Complex with non-zero imaginary + part. [Bug #5020] [ruby-dev:44088] + + * test/ruby/test_rational.rb (test_coerce): test for the above change. + Wed Aug 17 06:33:19 2011 Martin Bosslet * ext/openssl/ossl_x509cert.c: Add class documentation for @@ -38,6 +46,7 @@ Tue Aug 16 08:00:15 2011 Eric Hodel Mon Aug 15 09:58:55 2011 Martin Bosslet * ext/openssl/ossl_ssl.c: Support disabling OpenSSL compression. + * test/openssl/test_ssl.rb: Add a test for it. Thanks to Eric Wong for the patch. [Ruby 1.9 - Feature #5183] [ruby-core:38911] @@ -70,12 +79,14 @@ Sat Aug 13 09:26:24 2011 Aaron Patterson * ext/psych/lib/psych/core_ext.rb: Make Kernel#y private. [ruby-core:38913] + * test/psych/test_yaml.rb: corresponding test. Sat Aug 13 09:05:16 2011 Tadayoshi Funaba * ext/date/date_core.c (date_strftime_alloc): followed the change of r32885. + * doc/NEWS-1.9.3: followed the above change. Sat Aug 13 08:55:38 2011 Aaron Patterson @@ -228,7 +239,9 @@ Tue Aug 9 12:20:33 2011 Naohisa Goto Tue Aug 9 09:18:04 2011 Eric Hodel * ext/zlib/zlib.c (gzfile_wrap): Document encoding options. + * ext/zlib/zlib.c (rb_gzwriter_s_open): ditto + * ext/zlib/zlib.c (rb_gzreader_s_open): ditto Sun Aug 7 23:31:32 2011 KOSAKI Motohiro @@ -243,7 +256,9 @@ Sun Aug 7 22:51:45 2011 KOSAKI Motohiro * ext/openssl/ossl_asn1.c (decode_eoc): remove unused variables. Patch by Eric Wong. [Feature #5157] [ruby-core:38798] + * ext/openssl/ossl_asn1.c (ossl_asn1_decode): ditto. + * ext/openssl/ossl_pkey.c (ossl_pkey_new_from_data): ditto. Sun Aug 7 22:37:08 2011 KOSAKI Motohiro diff --git a/rational.c b/rational.c index 8dac978ca7..40b480df6e 100644 --- a/rational.c +++ b/rational.c @@ -1108,6 +1108,8 @@ nurat_coerce(VALUE self, VALUE other) if (k_exact_zero_p(RCOMPLEX(other)->imag)) return rb_assoc_new(f_rational_new_bang1 (CLASS_OF(self), RCOMPLEX(other)->real), self); + else + return rb_assoc_new(other, rb_Complex(self, INT2FIX(0))); } rb_raise(rb_eTypeError, "%s can't be coerced into %s", diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 3d9709517f..70aab03c38 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -721,6 +721,10 @@ class Rational_Test < Test::Unit::TestCase assert_equal([Rational(2),Rational(1)], Rational(1).coerce(2)) assert_equal([Rational(2.2),Rational(1)], Rational(1).coerce(2.2)) assert_equal([Rational(2),Rational(1)], Rational(1).coerce(Rational(2))) + + assert_nothing_raised(TypeError, '[Bug #5020] [ruby-devl:44088]') do + Rational(1,2).coerce(Complex(1,1)) + end end class ObjectX -- cgit v1.2.3