Annotation of OpenXM_contrib/gmp/mpbsd/mout.c, Revision 1.1.1.2
1.1 maekawa 1: /* mout(MINT) -- Do decimal output of MINT to standard output.
2:
1.1.1.2 ! maekawa 3: Copyright (C) 1991, 1994, 1996, 2000 Free Software Foundation, Inc.
1.1 maekawa 4:
5: This file is part of the GNU MP Library.
6:
7: The GNU MP Library is free software; you can redistribute it and/or modify
1.1.1.2 ! maekawa 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
1.1 maekawa 10: option) any later version.
11:
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
1.1.1.2 ! maekawa 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1.1 maekawa 15: License for more details.
16:
1.1.1.2 ! maekawa 17: You should have received a copy of the GNU Lesser General Public License
1.1 maekawa 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. */
21:
22: #include <stdio.h>
1.1.1.2 ! maekawa 23: #include <string.h>
1.1 maekawa 24: #include "mp.h"
25: #include "gmp.h"
26: #include "gmp-impl.h"
27:
28: void
29: #if __STDC__
30: mout (const MINT *x)
31: #else
32: mout (x)
33: const MINT *x;
34: #endif
35: {
36: mp_ptr xp;
37: mp_size_t x_size = x->_mp_size;
38: unsigned char *str;
39: size_t str_size;
40: char *num_to_text;
41: int i;
42: TMP_DECL (marker);
43:
44: if (x_size == 0)
45: {
46: fputc ('0', stdout);
47: return;
48: }
49: if (x_size < 0)
50: {
51: fputc ('-', stdout);
52: x_size = -x_size;
53: }
54:
55: TMP_MARK (marker);
56: str_size = ((size_t) (x_size * BITS_PER_MP_LIMB
57: * __mp_bases[10].chars_per_bit_exactly)) + 3;
58: str = (unsigned char *) TMP_ALLOC (str_size);
59:
60: /* Move the number to convert into temporary space, since mpn_get_str
61: clobbers its argument + needs one extra high limb.... */
62: xp = (mp_ptr) TMP_ALLOC ((x_size + 1) * BYTES_PER_MP_LIMB);
63: MPN_COPY (xp, x->_mp_d, x_size);
64:
65: str_size = mpn_get_str (str, 10, xp, x_size);
66:
67: /* mpn_get_str might make some leading zeros. Skip them. */
68: while (*str == 0)
69: {
70: str_size--;
71: str++;
72: }
73:
74: /* Translate to printable chars. */
75: for (i = 0; i < str_size; i++)
76: str[i] = "0123456789"[str[i]];
77: str[str_size] = 0;
78:
1.1.1.2 ! maekawa 79: str_size = strlen ((char *) str);
1.1 maekawa 80: if (str_size % 10 != 0)
81: {
82: fwrite (str, 1, str_size % 10, stdout);
83: str += str_size % 10;
84: str_size -= str_size % 10;
85: if (str_size != 0)
86: fputc (' ', stdout);
87: }
88: for (i = 0; i < str_size; i += 10)
89: {
90: fwrite (str, 1, 10, stdout);
91: str += 10;
92: if (i + 10 < str_size)
93: fputc (' ', stdout);
94: }
95: fputc ('\n', stdout);
96: TMP_FREE (marker);
97: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>