summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-11-17 12:47:14 +0000
committerzimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-11-17 12:47:14 +0000
commit0e09d16146daa9a74d9fd1f47991668d82cf6118 (patch)
tree5fc52f6c662c23e257b8044c0af193ab2529850a
parent8e8076b510016f82a5afd289bebbb44436b3af6b (diff)
downloadmpc-0e09d16146daa9a74d9fd1f47991668d82cf6118.tar.gz
[inp_str.c] allow i for imaginary part (in addition to I)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@323 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r--doc/mpc.texi4
-rw-r--r--src/inp_str.c2
-rw-r--r--tests/test.c22
3 files changed, 25 insertions, 3 deletions
diff --git a/doc/mpc.texi b/doc/mpc.texi
index b849226..5e4ea8d 100644
--- a/doc/mpc.texi
+++ b/doc/mpc.texi
@@ -890,8 +890,8 @@ if the base is 10 or less, alternatively @samp{MeN} or @samp{MEN}.
@samp{M} is the mantissa and
@samp{N} is the exponent. The mantissa is always in the specified base. The
exponent is always read in decimal.
-This function first reads the real part, then @code{+} followed by
-@code{I*} and the imaginary part.
+This function first reads the real part, then @code{+} or @code{-} followed by
+@code{I*} or @code{i*} and the absolute value of the imaginary part.
The argument @var{base} may be in the range 2 to 36.
diff --git a/src/inp_str.c b/src/inp_str.c
index ed14994..18847cd 100644
--- a/src/inp_str.c
+++ b/src/inp_str.c
@@ -63,7 +63,7 @@ mpc_inp_str (mpc_ptr rop, FILE *stream, int base, mpc_rnd_t rnd_mode)
c = getc (stream);
size ++;
- if (c != 'I')
+ if (c != 'I' && c != 'i')
return 0; /* error */
c = getc (stream);
diff --git a/tests/test.c b/tests/test.c
index 59f674d..cca3f14 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -106,6 +106,28 @@ main (void)
fprintf (stderr, "\n");
exit (1);
}
+ /* other test with i instead of I */
+ file = fopen (filename, "w");
+ fprintf (file, "1 -i*1\n");
+ fclose (file);
+ file = fopen (filename, "r");
+ if (mpc_inp_str (z, file, 10, MPC_RNDUZ) == 0)
+ {
+ fprintf (stderr, "mpc_inp_str cannot correctly re-read number "
+ "in file %s\n", filename);
+ exit (1);
+ }
+ fclose (file);
+ mpc_set_si_si (x, 1, -1, MPC_RNDNN);
+ mpfr_clear_flags ();
+ if (mpc_cmp (z, x) != 0 || mpfr_erangeflag_p())
+ {
+ fprintf (stderr, "mpc_inp_str do not correctly re-read number\n");
+ mpc_out_str (stderr, 10, 0, z, MPC_RNDNN);
+ fprintf (stderr, "\n");
+ exit (1);
+ }
+
/* other test with invalid real part */
file = fopen (filename, "w"); /* should work now */
fprintf (file, "invalid_real_part +I*1\n");