Add support for 64 bits integers.

Fix issue #306
This commit is contained in:
Tony Bellavia 2020-06-12 06:24:19 +02:00
parent 4db99f4012
commit b61ed2106b

View File

@ -1,32 +1,39 @@
#include <lib.h> #include <lib.h>
/* Integer to ASCII for signed decimal integers. */ /* Integer to ASCII for signed decimal integers. */
static int next; static char qbuf[12];
static char qbuf[8];
char *itoa(int n); char *itoa(int n);
char *itoa(int n) char *itoa(int n)
{ {
register int r, k; register int r;
register int k;
int flag = 0; int flag = 0;
long long nb = n;
int next = 0;
next = 0; if (nb < 0)
if (n < 0) { {
qbuf[next++] = '-'; qbuf[next++] = '-';
n = -n; nb = -nb;
} }
if (n == 0) { if (nb == 0)
{
qbuf[next++] = '0'; qbuf[next++] = '0';
} else { }
k = 10000; else
while (k > 0) { {
r = n / k; k = 1000000000;
if (flag || r > 0) { while (k > 0)
{
r = nb / k;
if (flag || r > 0)
{
qbuf[next++] = '0' + r; qbuf[next++] = '0' + r;
flag = 1; flag = 1;
} }
n -= r * k; nb -= r * k;
k = k / 10; k = k / 10;
} }
} }