aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-03 16:43:01 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-03 16:43:01 +0000
commitef38a43c50aa88f7e0e03f86aa5868dee91e449c (patch)
treed7e3b213bd314bd46e3c4891eee58132b97cb7e3
parent28c53aabcad4ec41916ad5e72203022769ab73f5 (diff)
downloadruby-ef38a43c50aa88f7e0e03f86aa5868dee91e449c.tar.gz
* complex.c (nurat_{to_s,inspect}): provides better representation
for in-finite imag part. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--complex.c15
-rw-r--r--test/ruby/test_complex.rb10
3 files changed, 20 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 4b04058ec6..5f78f0a43d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Dec 4 01:37:47 2008 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * complex.c (nurat_{to_s,inspect}): provides better representation
+ for in-finite imag part.
+
Thu Dec 4 01:22:41 2008 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c (f_signbit): NaN may be signed value.
diff --git a/complex.c b/complex.c
index 4230af22d6..70eba23ec7 100644
--- a/complex.c
+++ b/complex.c
@@ -922,6 +922,8 @@ nucomp_to_s(VALUE self)
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,18 +932,11 @@ nucomp_to_s(VALUE self)
static VALUE
nucomp_inspect(VALUE self)
{
- VALUE s, impos;
-
- get_dat1(self);
-
- impos = f_tpositive_p(dat->imag);
+ VALUE s;
s = rb_str_new2("(");
- rb_str_concat(s, f_inspect(dat->real));
- rb_str_cat2(s, !impos ? "-" : "+");
-
- rb_str_concat(s, f_inspect(f_abs(dat->imag)));
- rb_str_cat2(s, "i)");
+ rb_str_concat(s, nucomp_to_s(self));
+ rb_str_cat2(s, ")");
return s;
}
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index 2a193eb155..5d4916e1d0 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -564,6 +564,16 @@ class Complex_Test < Test::Unit::TestCase
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