~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gmp3/mpbsd/mout.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* mout(MINT) -- Do decimal output of MINT to standard output.
 
2
 
 
3
Copyright 1991, 1994, 1996, 2000, 2001 Free Software Foundation, Inc.
 
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
 
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.
 
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
 
14
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
License for more details.
 
16
 
 
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. */
 
21
 
 
22
#include <stdio.h>
 
23
#include <string.h>
 
24
#include "mp.h"
 
25
#include "gmp.h"
 
26
#include "gmp-impl.h"
 
27
 
 
28
void
 
29
mout (const MINT *x)
 
30
{
 
31
  mp_ptr xp;
 
32
  mp_size_t x_size = x->_mp_size;
 
33
  unsigned char *str;
 
34
  size_t str_size;
 
35
  int i;
 
36
  TMP_DECL (marker);
 
37
 
 
38
  if (x_size == 0)
 
39
    {
 
40
      fputc ('0', stdout);
 
41
      fputc ('\n', stdout);
 
42
      return;
 
43
    }
 
44
  if (x_size < 0)
 
45
    {
 
46
      fputc ('-', stdout);
 
47
      x_size = -x_size;
 
48
    }
 
49
 
 
50
  TMP_MARK (marker);
 
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);
 
54
 
 
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);
 
59
 
 
60
  str_size = mpn_get_str (str, 10, xp, x_size);
 
61
 
 
62
  /* mpn_get_str might make some leading zeros.  Skip them.  */
 
63
  while (*str == 0)
 
64
    {
 
65
      str_size--;
 
66
      str++;
 
67
    }
 
68
 
 
69
  /* Translate to printable chars.  */
 
70
  for (i = 0; i < str_size; i++)
 
71
    str[i] = "0123456789"[str[i]];
 
72
  str[str_size] = 0;
 
73
 
 
74
  str_size = strlen ((char *) str);
 
75
  if (str_size % 10 != 0)
 
76
    {
 
77
      fwrite (str, 1, str_size % 10, stdout);
 
78
      str += str_size % 10;
 
79
      str_size -= str_size % 10;
 
80
      if (str_size != 0)
 
81
        fputc (' ', stdout);
 
82
    }
 
83
  for (i = 0; i < str_size; i += 10)
 
84
    {
 
85
      fwrite (str, 1, 10, stdout);
 
86
      str += 10;
 
87
      if (i + 10 < str_size)
 
88
        fputc (' ', stdout);
 
89
    }
 
90
  fputc ('\n', stdout);
 
91
  TMP_FREE (marker);
 
92
}