1 /* mpz_set_str(mp_dest, string, base) -- Convert the \0-terminated
2 string STRING in base BASE to multiple precision integer in
3 MP_DEST. Allow white space in the string. If BASE == 0 determine
4 the base in the C standard way, i.e. 0xhh...h means base 16,
5 0oo...o means base 8, otherwise assume base 10.
7 Copyright (C) 1991, 1993, 1994, Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Library General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
19 License for more details.
21 You should have received a copy of the GNU Library General Public License
22 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 MA 02111-1307, USA. */
32 digit_value_in_base (c, base)
54 mpz_set_str (mpz_ptr x, const char *str, int base)
56 mpz_set_str (x, str, base)
70 /* Skip whitespace. */
82 if (digit_value_in_base (c, base == 0 ? 10 : base) < 0)
83 return -1; /* error if no digits */
85 /* If BASE is 0, try to find out the base by looking at the initial
94 if (c == 'x' || c == 'X')
103 str_size = strlen (str - 1);
104 s = begs = (char *) TMP_ALLOC (str_size + 1);
106 for (i = 0; i < str_size; i++)
110 int dig = digit_value_in_base (c, base);
123 xsize = str_size / __mp_bases[base].chars_per_limb + 1;
124 if (x->_mp_alloc < xsize)
125 _mpz_realloc (x, xsize);
127 xsize = mpn_set_str (x->_mp_d, (unsigned char *) begs, str_size, base);
128 x->_mp_size = negative ? -xsize : xsize;