1 /* mout(MINT) -- Do decimal output of MINT to standard output.
3 Copyright (C) 1991, 1994, 1996 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Library General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
36 mp_size_t x_size = x->_mp_size;
55 str_size = ((size_t) (x_size * BITS_PER_MP_LIMB
56 * __mp_bases[10].chars_per_bit_exactly)) + 3;
57 str = (unsigned char *) TMP_ALLOC (str_size);
59 /* Move the number to convert into temporary space, since mpn_get_str
60 clobbers its argument + needs one extra high limb.... */
61 xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB);
62 MPN_COPY (xp, x->_mp_d, x_size);
64 str_size = mpn_get_str (str, 10, xp, x_size);
66 /* mpn_get_str might make some leading zeros. Skip them. */
73 /* Translate to printable chars. */
74 for (i = 0; i < str_size; i++)
75 str[i] = "0123456789"[str[i]];
78 str_size = strlen (str);
79 if (str_size % 10 != 0)
81 fwrite (str, 1, str_size % 10, stdout);
83 str_size -= str_size % 10;
87 for (i = 0; i < str_size; i += 10)
89 fwrite (str, 1, 10, stdout);
91 if (i + 10 < str_size)