#include <ncbi.h>
#include <gishlib.h>

/*
	longwidth10(i)

	return the length (in characters) of the ASCII base 10 representation
	of the specified integer.
*/
int _cdecl
longwidth10(i)
	long	i;
{
	int	width;

	if (i == 0)
		return 1;

	if (i < 0)
		width = 1;
	else
		width = 0;

	i = ABS(i);
	/* A binary search would be faster! */
	if (i < 10)
		return width+1;
	if (i < 100)
		return width+2;
	if (i < 1000)
		return width+3;
	if (i < 10000)
		return width+4;
	if (i < 100000)
		return width+5;
	if (i < 1000000)
		return width+6;
	if (i < 10000000)
		return width+7;
	if (i < 100000000)
		return width+8;
	if (i < 1000000000)
		return width+9;
#ifndef Int8
	return width+10;
#else
	if (i < 10000000000)
		return width+10;
	if (i < 100000000000)
		return width+11;
	if (i < 1000000000000)
		return width+12;
	if (i < 10000000000000)
		return width+13;
	if (i < 100000000000000)
		return width+14;
	if (i < 1000000000000000)
		return width+15;
	if (i < 10000000000000000)
		return width+16;
	if (i < 100000000000000000)
		return width+17;
	if (i < 1000000000000000000)
		return width+18;
	return width+19;
#endif
}

/*
	ulongwidth10(i)

	return the length (in characters) of the ASCII base 10 representation
	of the specified unsigned integer.
*/
int _cdecl
ulongwidth10(i)
	unsigned long	i;
{
	/* A binary search would be faster! */
	if (i < 10)
		return 1;
	if (i < 100)
		return 2;
	if (i < 1000)
		return 3;
	if (i < 10000)
		return 4;
	if (i < 100000)
		return 5;
	if (i < 1000000)
		return 6;
	if (i < 10000000)
		return 7;
	if (i < 100000000)
		return 8;
	if (i < 1000000000)
		return 9;
#ifndef Int8
	return 10;
#else
	if (i < 10000000000)
		return 10;
	if (i < 100000000000)
		return 11;
	if (i < 1000000000000)
		return 12;
	if (i < 10000000000000)
		return 13;
	if (i < 100000000000000)
		return 14;
	if (i < 1000000000000000)
		return 15;
	if (i < 10000000000000000)
		return 16;
	if (i < 100000000000000000)
		return 17;
	if (i < 1000000000000000000)
		return 18;
	return 19;
#endif
}
