1 /* mpc_strtoc -- Read a complex number from a string.
3 Copyright (C) 2009, 2010, 2011 INRIA
5 This file is part of GNU MPC.
7 GNU MPC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/ .
26 skip_whitespace (const char **p
)
28 /* TODO: This function had better be inlined, but it is unclear whether
29 the hassle to get this implemented across all platforms is worth it. */
30 while (isspace ((unsigned char) **p
))
35 mpc_strtoc (mpc_ptr rop
, const char *nptr
, char **endptr
, int base
, mpc_rnd_t rnd
)
41 int inex_re
= 0, inex_im
= 0;
43 if (nptr
== NULL
|| base
> 36 || base
== 1)
54 inex_re
= mpfr_strtofr (mpc_realref(rop
), p
, &end
, base
, MPC_RND_RE (rnd
));
60 inex_im
= mpfr_set_ui (mpc_imagref (rop
), 0ul, GMP_RNDN
);
62 if (!isspace ((unsigned char)*p
))
67 inex_im
= mpfr_strtofr (mpc_imagref(rop
), p
, &end
, base
, MPC_RND_IM (rnd
));
81 return MPC_INEX (inex_re
, inex_im
);
85 *endptr
= (char*) nptr
;
86 mpfr_set_nan (mpc_realref (rop
));
87 mpfr_set_nan (mpc_imagref (rop
));