summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-05 13:34:55 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-05 13:34:55 +0000
commita0b0c4e51eaf5580cb0460b726e3d4fa70b47b1c (patch)
tree18b8332fd3cbe7a5836c7ef00aa19dddd2cbf5f9 /complex.c
parent28053a8867cee1c2d21050a752cfeab295bd6ecb (diff)
merges r20546 from trunk into ruby-1_9_1.
* complex.c: inpsect should not depend on to_s. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@20557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/complex.c b/complex.c
index 70eba23ec7..f69c976ac0 100644
--- a/complex.c
+++ b/complex.c
@@ -910,7 +910,7 @@ f_tpositive_p(VALUE x)
}
static VALUE
-nucomp_to_s(VALUE self)
+nucomp_format(VALUE self, VALUE (*func)(VALUE))
{
VALUE s, impos;
@@ -918,10 +918,10 @@ nucomp_to_s(VALUE self)
impos = f_tpositive_p(dat->imag);
- s = f_to_s(dat->real);
+ s = (*func)(dat->real);
rb_str_cat2(s, !impos ? "-" : "+");
- rb_str_concat(s, f_to_s(f_abs(dat->imag)));
+ rb_str_concat(s, (*func)(f_abs(dat->imag)));
if (!rb_isdigit(RSTRING_PTR(s)[RSTRING_LEN(s) - 1]))
rb_str_cat2(s, "*");
rb_str_cat2(s, "i");
@@ -930,12 +930,18 @@ nucomp_to_s(VALUE self)
}
static VALUE
+nucomp_to_s(VALUE self)
+{
+ return nucomp_format(self, f_to_s);
+}
+
+static VALUE
nucomp_inspect(VALUE self)
{
VALUE s;
s = rb_str_new2("(");
- rb_str_concat(s, nucomp_to_s(self));
+ rb_str_concat(s, nucomp_format(self, f_inspect));
rb_str_cat2(s, ")");
return s;