1
/* mout(MINT) -- Do decimal output of MINT to standard output.
3
Copyright 1991, 1994, 1996, 2000, 2001 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 Lesser General Public License as published by
9
the Free Software Foundation; either version 2.1 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 Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU Lesser 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. */
32
mp_size_t x_size = x->_mp_size;
51
str_size = ((size_t) (x_size * BITS_PER_MP_LIMB
52
* __mp_bases[10].chars_per_bit_exactly)) + 3;
53
str = (unsigned char *) TMP_ALLOC (str_size);
55
/* Move the number to convert into temporary space, since mpn_get_str
56
clobbers its argument + needs one extra high limb.... */
57
xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB);
58
MPN_COPY (xp, x->_mp_d, x_size);
60
str_size = mpn_get_str (str, 10, xp, x_size);
62
/* mpn_get_str might make some leading zeros. Skip them. */
69
/* Translate to printable chars. */
70
for (i = 0; i < str_size; i++)
71
str[i] = "0123456789"[str[i]];
74
str_size = strlen ((char *) str);
75
if (str_size % 10 != 0)
77
fwrite (str, 1, str_size % 10, stdout);
79
str_size -= str_size % 10;
83
for (i = 0; i < str_size; i += 10)
85
fwrite (str, 1, 10, stdout);
87
if (i + 10 < str_size)