ruby-changes:8965
From: yugui <ko1@a...>
Date: Thu, 4 Dec 2008 17:56:47 +0900 (JST)
Subject: [ruby-changes:8965] Ruby:r20502 (ruby_1_9_1): merges r20474 from trunk into ruby_1_9_1.
yugui 2008-12-04 17:55:20 +0900 (Thu, 04 Dec 2008) New Revision: 20502 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20502 Log: merges r20474 from trunk into ruby_1_9_1. * complex.c (nurat_{to_s,inspect}): provides better representation for in-finite imag part. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/complex.c branches/ruby_1_9_1/test/ruby/test_complex.rb Index: ruby_1_9_1/complex.c =================================================================== --- ruby_1_9_1/complex.c (revision 20501) +++ ruby_1_9_1/complex.c (revision 20502) @@ -922,6 +922,8 @@ rb_str_cat2(s, !impos ? "-" : "+"); rb_str_concat(s, f_to_s(f_abs(dat->imag))); + if (!rb_isdigit(RSTRING_PTR(s)[RSTRING_LEN(s) - 1])) + rb_str_cat2(s, "*"); rb_str_cat2(s, "i"); return s; @@ -930,19 +932,12 @@ static VALUE nucomp_inspect(VALUE self) { - VALUE s, impos; + VALUE s; - get_dat1(self); - - impos = f_tpositive_p(dat->imag); - s = rb_str_new2("("); - rb_str_concat(s, f_inspect(dat->real)); - rb_str_cat2(s, !impos ? "-" : "+"); + rb_str_concat(s, nucomp_to_s(self)); + rb_str_cat2(s, ")"); - rb_str_concat(s, f_inspect(f_abs(dat->imag))); - rb_str_cat2(s, "i)"); - return s; } Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20501) +++ ruby_1_9_1/ChangeLog (revision 20502) @@ -1,3 +1,8 @@ +Thu Dec 4 01:37:47 2008 Tadayoshi Funaba <tadf@d...> + + * complex.c (nurat_{to_s,inspect}): provides better representation + for in-finite imag part. + Thu Dec 4 01:22:41 2008 Tadayoshi Funaba <tadf@d...> * complex.c (f_signbit): NaN may be signed value. Index: ruby_1_9_1/test/ruby/test_complex.rb =================================================================== --- ruby_1_9_1/test/ruby/test_complex.rb (revision 20501) +++ ruby_1_9_1/test/ruby/test_complex.rb (revision 20502) @@ -564,6 +564,16 @@ assert_equal('1-2/3i', Complex(1,Rational(-2,3)).to_s) assert_equal('-1-2/3i', Complex(-1,Rational(-2,3)).to_s) end + + nan = 0.0 / 0 + inf = 1.0 / 0 + if nan.nan? + assert_equal('NaN+NaN*i', Complex(nan,nan).to_s) + end + if inf.infinite? + assert_equal('Infinity+Infinity*i', Complex(inf,inf).to_s) + assert_equal('Infinity-Infinity*i', Complex(inf,-inf).to_s) + end end def test_inspect -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/