summaryrefslogtreecommitdiff
path: root/inp_str.c
diff options
context:
space:
mode:
Diffstat (limited to 'inp_str.c')
-rw-r--r--inp_str.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/inp_str.c b/inp_str.c
new file mode 100644
index 0000000..8d0c8e8
--- /dev/null
+++ b/inp_str.c
@@ -0,0 +1,65 @@
+/* mpc_inp_str -- Input a complex number from a given stream.
+
+Copyright (C) 2002 Andreas Enge, Paul Zimmermann
+
+This file is part of the MPC Library.
+
+The MPC Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPC Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPC Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include <ctype.h>
+#include "gmp.h"
+#include "mpfr.h"
+#include "mpc.h"
+
+size_t
+mpc_inp_str (mpc_ptr rop, FILE *stream, int base, mp_rnd_t rnd_mode)
+{
+ size_t size, size_im;
+ int c;
+
+ /* input real part */
+ size = mpfr_inp_str (MPC_RE(rop), stream, base, MPC_RND_RE(rnd_mode));
+ if (size == 0) /* error while reading the real part */
+ return 0;
+
+ /* get 'i' or 'I' followed by '*' */
+ do
+ {
+ c = getc (stream);
+ size ++;
+ }
+ while (isspace (c));
+
+ if (c != '+')
+ return 0; /* error */
+
+ c = getc (stream);
+ size ++;
+ if (c != 'I')
+ return 0; /* error */
+
+ c = getc (stream);
+ size ++;
+ if (c != '*')
+ return 0; /* error */
+
+ 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;
+
+ return size + size_im;
+}