summaryrefslogtreecommitdiff
path: root/src/inp_str.c
diff options
context:
space:
mode:
authorthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-06-06 15:02:58 +0000
committerthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-06-06 15:02:58 +0000
commit138da50ae2f72b722d0a2ab40feae1c936e6efce (patch)
treeceb74e1491194ffaeea8a4ba863594a890f5a4a7 /src/inp_str.c
parent5bb05823a908afe21950ec2db5c0a23c9024ff8a (diff)
downloadmpc-138da50ae2f72b722d0a2ab40feae1c936e6efce.tar.gz
src/out_str.c, src/inp_str.c: change output to "A +I*B" format with a space
separating the real and the imaginary part. tests/test.c: Fix mpc_out_str test. git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@151 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'src/inp_str.c')
-rw-r--r--src/inp_str.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/inp_str.c b/src/inp_str.c
index eaade41..c53e92d 100644
--- a/src/inp_str.c
+++ b/src/inp_str.c
@@ -30,6 +30,7 @@ mpc_inp_str (mpc_ptr rop, FILE *stream, int base, mpc_rnd_t rnd_mode)
{
size_t size, size_im;
int c;
+ int sign;
if (stream == NULL)
stream = stdin;
@@ -47,8 +48,18 @@ mpc_inp_str (mpc_ptr rop, FILE *stream, int base, mpc_rnd_t rnd_mode)
}
while (isspace (c));
- if (c != '+')
- return 0; /* error */
+ switch (c)
+ {
+ case '+':
+ sign = 0;
+ break;
+ case '-':
+ sign = 1;
+ break;
+ default:
+ /* error */
+ return 0;
+ }
c = getc (stream);
size ++;
@@ -63,6 +74,9 @@ mpc_inp_str (mpc_ptr rop, FILE *stream, int base, mpc_rnd_t rnd_mode)
size_im = mpfr_inp_str (MPC_IM(rop), stream, base, MPC_RND_IM(rnd_mode));
if (size_im == 0) /* error while reading the imaginary part */
return 0;
+
+ if (sign)
+ mpfr_setsign (MPC_IM (rop), MPC_IM (rop), sign, GMP_RNDN);
return size + size_im;
}