diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-17 17:50:22 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-17 17:50:22 +0000 |
commit | aa5cf4f74446601e854f3841a0aab74e9fa229f5 (patch) | |
tree | cd05037f157f0df5b14c0c45873128960d3c8be2 /src/strtoc.c | |
parent | 9dd0f23159d01367a93776126415607fd52decd9 (diff) | |
download | mpc-aa5cf4f74446601e854f3841a0aab74e9fa229f5.tar.gz |
revert to UNIX format (r457 changed every file to DOS format).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@459 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'src/strtoc.c')
-rw-r--r-- | src/strtoc.c | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/src/strtoc.c b/src/strtoc.c index 737e3d9..cd3e2d7 100644 --- a/src/strtoc.c +++ b/src/strtoc.c @@ -1,91 +1,91 @@ -/* mpc_strtoc -- Read a complex number from a string.
-
-Copyright (C) 2009 Philippe Th\'eveny
-
-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 <string.h>
-#include <ctype.h>
-#include <stdio.h>
-#include "mpc-impl.h"
-
-#include "config.h"
-
-int
-mpc_strtoc (mpc_ptr rop, char *nptr, char **endptr, int base, mpc_rnd_t rnd)
-{
- char *p;
- char *end;
- int bracketed = 0;
-
- int inex_re = 0;
- int inex_im = 0;
-
- if (base != 0 && (base < 2 || base > 62))
- goto error;
-
- if (nptr == NULL)
- goto error;
-
- p = nptr;
- for (p = nptr; isspace (*p); ++p);
-
- if (*p == '(')
- {
- bracketed = 1;
- ++p;
- }
-
- inex_re = mpfr_strtofr (MPC_RE(rop), p, &end, base, MPC_RND_RE (rnd));
- if (end == p)
- goto error;
- p = end;
-
- if (bracketed)
- {
- if (!isspace (*p))
- goto error;
-
- for (++p; isspace (*p); ++p);
-
- inex_im = mpfr_strtofr (MPC_IM(rop), p, &end, base, MPC_RND_IM (rnd));
- if (end == p)
- goto error;
- p = end;
-
- if (*p != ')')
- goto error;
-
- p++;
- }
- else
- inex_im = mpfr_set_ui (MPC_IM (rop), 0, MPC_RND_IM(rnd));
-
- for (; isspace (*p); ++p);
-
- if (endptr != NULL)
- *endptr = p;
- return MPC_INEX (inex_re, inex_im);
-
- error:
- if (endptr != NULL)
- *endptr = nptr;
- mpfr_set_nan (MPC_RE (rop));
- mpfr_set_nan (MPC_IM (rop));
- return 0;
-}
+/* mpc_strtoc -- Read a complex number from a string. + +Copyright (C) 2009 Philippe Th\'eveny + +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 <string.h> +#include <ctype.h> +#include <stdio.h> +#include "mpc-impl.h" + +#include "config.h" + +int +mpc_strtoc (mpc_ptr rop, char *nptr, char **endptr, int base, mpc_rnd_t rnd) +{ + char *p; + char *end; + int bracketed = 0; + + int inex_re = 0; + int inex_im = 0; + + if (base != 0 && (base < 2 || base > 62)) + goto error; + + if (nptr == NULL) + goto error; + + p = nptr; + for (p = nptr; isspace (*p); ++p); + + if (*p == '(') + { + bracketed = 1; + ++p; + } + + inex_re = mpfr_strtofr (MPC_RE(rop), p, &end, base, MPC_RND_RE (rnd)); + if (end == p) + goto error; + p = end; + + if (bracketed) + { + if (!isspace (*p)) + goto error; + + for (++p; isspace (*p); ++p); + + inex_im = mpfr_strtofr (MPC_IM(rop), p, &end, base, MPC_RND_IM (rnd)); + if (end == p) + goto error; + p = end; + + if (*p != ')') + goto error; + + p++; + } + else + inex_im = mpfr_set_ui (MPC_IM (rop), 0, MPC_RND_IM(rnd)); + + for (; isspace (*p); ++p); + + if (endptr != NULL) + *endptr = p; + return MPC_INEX (inex_re, inex_im); + + error: + if (endptr != NULL) + *endptr = nptr; + mpfr_set_nan (MPC_RE (rop)); + mpfr_set_nan (MPC_IM (rop)); + return 0; +} |