1 /* mpz_out_str(stream, base, integer) -- Output to STREAM the multi prec.
2 integer INTEGER in base BASE.
4 Copyright 1991, 1993, 1994, 1996, 2001, 2005 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
26 mpz_out_str (FILE *stream, int base, mpz_srcptr x)
29 mp_size_t x_size = x->_mp_size;
42 num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz";
47 num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
55 num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
61 return ferror (stream) ? 0 : 1;
74 str_size = ((size_t) (x_size * GMP_LIMB_BITS
75 * mp_bases[base].chars_per_bit_exactly)) + 3;
76 str = (unsigned char *) TMP_ALLOC (str_size);
78 /* Move the number to convert into temporary space, since mpn_get_str
79 clobbers its argument + needs one extra high limb.... */
80 xp = TMP_ALLOC_LIMBS (x_size + 1);
81 MPN_COPY (xp, x->_mp_d, x_size);
83 str_size = mpn_get_str (str, base, xp, x_size);
85 /* mpn_get_str might make some leading zeros. Skip them. */
92 /* Translate to printable chars. */
93 for (i = 0; i < str_size; i++)
94 str[i] = num_to_text[str[i]];
99 fwret = fwrite ((char *) str, 1, str_size, stream);
104 return ferror (stream) ? 0 : written;