[前][次][番号順一覧][スレッド一覧]

ruby-changes:8938

From: tadf <ko1@a...>
Date: Thu, 4 Dec 2008 01:43:19 +0900 (JST)
Subject: [ruby-changes:8938] Ruby:r20474 (trunk): * complex.c (nurat_{to_s,inspect}): provides better representation

tadf	2008-12-04 01:43:01 +0900 (Thu, 04 Dec 2008)

  New Revision: 20474

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20474

  Log:
    * complex.c (nurat_{to_s,inspect}): provides better representation
      for in-finite imag part.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/test/ruby/test_complex.rb

Index: complex.c
===================================================================
--- complex.c	(revision 20473)
+++ complex.c	(revision 20474)
@@ -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: ChangeLog
===================================================================
--- ChangeLog	(revision 20473)
+++ ChangeLog	(revision 20474)
@@ -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: test/ruby/test_complex.rb
===================================================================
--- test/ruby/test_complex.rb	(revision 20473)
+++ test/ruby/test_complex.rb	(revision 20474)
@@ -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/

[前][次][番号順一覧][スレッド一覧]