1151497Sru/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2002, 2004
2104862Sru     Free Software Foundation, Inc.
375584Sru     Written by James Clark (jjc@jclark.com)
475584Sru
575584SruThis file is part of groff.
675584Sru
775584Srugroff is free software; you can redistribute it and/or modify it under
875584Sruthe terms of the GNU General Public License as published by the Free
975584SruSoftware Foundation; either version 2, or (at your option) any later
1075584Sruversion.
1175584Sru
1275584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
1375584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
1475584SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1575584Srufor more details.
1675584Sru
1775584SruYou should have received a copy of the GNU General Public License along
1875584Sruwith groff; see the file COPYING.  If not, write to the Free Software
19151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
2075584Sru
2175584Sru#define INT_DIGITS 19		/* enough for 64 bit integer */
22104862Sru#define UINT_DIGITS 20
2375584Sru
24151497Sru#ifdef __cplusplus
25151497Sruextern "C" {
26151497Sru#endif
27151497Sru
28151497Sruchar *i_to_a(int i)
2975584Sru{
3075584Sru  /* Room for INT_DIGITS digits, - and '\0' */
3175584Sru  static char buf[INT_DIGITS + 2];
3275584Sru  char *p = buf + INT_DIGITS + 1;	/* points to terminating '\0' */
3375584Sru  if (i >= 0) {
3475584Sru    do {
3575584Sru      *--p = '0' + (i % 10);
3675584Sru      i /= 10;
3775584Sru    } while (i != 0);
3875584Sru    return p;
3975584Sru  }
4075584Sru  else {			/* i < 0 */
4175584Sru    do {
4275584Sru      *--p = '0' - (i % 10);
4375584Sru      i /= 10;
4475584Sru    } while (i != 0);
4575584Sru    *--p = '-';
4675584Sru  }
4775584Sru  return p;
4875584Sru}
49104862Sru
50151497Sruchar *ui_to_a(unsigned int i)
51104862Sru{
52104862Sru  /* Room for UINT_DIGITS digits and '\0' */
53104862Sru  static char buf[UINT_DIGITS + 1];
54104862Sru  char *p = buf + UINT_DIGITS;	/* points to terminating '\0' */
55104862Sru  do {
56104862Sru    *--p = '0' + (i % 10);
57104862Sru    i /= 10;
58104862Sru  } while (i != 0);
59104862Sru  return p;
60104862Sru}
61151497Sru
62151497Sru#ifdef __cplusplus
63151497Sru}
64151497Sru#endif
65