summaryrefslogtreecommitdiff
path: root/src/out_str.c
diff options
context:
space:
mode:
authorenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-03-19 17:05:09 +0000
committerenge <enge@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2009-03-19 17:05:09 +0000
commit4c14321905768e1a782384c38c49a9c66e3c1308 (patch)
treef27a1e4344bbd162916d9f2eab8f3fb5d8f49569 /src/out_str.c
parent2e8fe025b2ac45daec5a2c1b0437b71b7e36c1a6 (diff)
downloadmpc-4c14321905768e1a782384c38c49a9c66e3c1308.tar.gz
inp_str, out_str: totally rewritten according to the format of strtoc;
inp_str sets the number to nan+i*nan in case of an error git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@483 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'src/out_str.c')
-rw-r--r--src/out_str.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/out_str.c b/src/out_str.c
index f0a724f..080130e 100644
--- a/src/out_str.c
+++ b/src/out_str.c
@@ -1,6 +1,6 @@
/* mpc_out_str -- Output a complex number on a given stream.
-Copyright (C) 2002, 2009 Andreas Enge, Paul Zimmermann, Philippe Th\'eveny
+Copyright (C) 2009 Andreas Enge
This file is part of the MPC Library.
@@ -24,25 +24,17 @@ MA 02111-1307, USA. */
#include "mpc-impl.h"
size_t
-mpc_out_str (FILE *stream, int base, size_t n, mpc_srcptr op, mpc_rnd_t rnd)
-{
- mpfr_t positive_imag;
- size_t size;
-
- if (stream == NULL)
- stream = stdout; /* fprintf does not allow NULL as first argument */
-
- size = mpfr_out_str (stream, base, n, MPC_RE(op), MPC_RND_RE(rnd));
-
- positive_imag[0] = MPC_IM (op)[0];
- if (mpfr_signbit (MPC_IM (op)))
- {
- size += fprintf (stream, " -I*");
- mpfr_setsign (positive_imag, positive_imag, 0, GMP_RNDN);
- }
- else
- size += fprintf (stream, " +I*");
- size += mpfr_out_str (stream, base, n, positive_imag, MPC_RND_IM(rnd));
-
- return size;
+mpc_out_str (FILE *stream, int base, size_t n, mpc_srcptr op, mpc_rnd_t rnd) {
+ size_t size = 3; /* for '(', ' ' and ')' */
+
+ if (stream == NULL)
+ stream = stdout; /* fprintf does not allow NULL as first argument */
+
+ fprintf (stream, "(");
+ size += mpfr_out_str (stream, base, n, MPC_RE(op), MPC_RND_RE(rnd));
+ fprintf (stream, " ");
+ size += mpfr_out_str (stream, base, n, MPC_IM(op), MPC_RND_RE(rnd));
+ fprintf (stream, ")");
+
+ return size;
}