src/backend/utils/adt/numutils.c
int
pg_ulltoa_n(uint64 value, char *a)
{
	int			olength,
				i = 0;
	uint32		value2;

	/* Degenerate case */
	if (value == 0)
	{
		*a = '0';
		return 1;
	}

	olength = decimalLength64(value);

	/* Compute the result string. */
	while (value >= 100000000)
	{
		const uint64 q = value / 100000000;
		uint32		value2 = (uint32) (value - 100000000 * q);

		const uint32 c = value2 % 10000;
		const uint32 d = value2 / 10000;
		const uint32 c0 = (c % 100) << 1;
		const uint32 c1 = (c / 100) << 1;
		const uint32 d0 = (d % 100) << 1;
		const uint32 d1 = (d / 100) << 1;

		char	   *pos = a + olength - i;

		value = q;

		memcpy(pos - 2, DIGIT_TABLE + c0, 2);
		memcpy(pos - 4, DIGIT_TABLE + c1, 2);
		memcpy(pos - 6, DIGIT_TABLE + d0, 2);
		memcpy(pos - 8, DIGIT_TABLE + d1, 2);
		i += 8;
	}

	/* Switch to 32-bit for speed */
	value2 = (uint32) value;

	if (value2 >= 10000)
	{
		const uint32 c = value2 - 10000 * (value2 / 10000);
		const uint32 c0 = (c % 100) << 1;
		const uint32 c1 = (c / 100) << 1;

		char	   *pos = a + olength - i;

		value2 /= 10000;

		memcpy(pos - 2, DIGIT_TABLE + c0, 2);
		memcpy(pos - 4, DIGIT_TABLE + c1, 2);
		i += 4;
	}
	if (value2 >= 100)
	{
		const uint32 c = (value2 % 100) << 1;
		char	   *pos = a + olength - i;

		value2 /= 100;

		memcpy(pos - 2, DIGIT_TABLE + c, 2);
		i += 2;
	}
	if (value2 >= 10)
	{
		const uint32 c = value2 << 1;
		char	   *pos = a + olength - i;

		memcpy(pos - 2, DIGIT_TABLE + c, 2);
	}
	else
		*a = (char) ('0' + value2);

	return olength;
}
/*
 * Get the decimal representation, not NUL-terminated, and return the length of
 * same.  Caller must ensure that a points to at least MAXINT8LEN bytes.
 */
Get the decimal representation, not NUL-terminated, and return the length of
same.  Caller must ensure that a points to at least MAXINT8LEN bytes.
Get the decimal representation not NUL - terminated and return the length of same . Caller must ensure that a points to at least MAXINT8LEN bytes .
int
pg_ulltoa_n(uint64 value, char *a)
{
	int			olength,
				i = 0;
	uint32		value2;
	if (value == 0)
	{
		*a = '0';
		return 1;
	}
	olength = decimalLength64(value);
	while (value >= 100000000)
	{
		const uint64 q = value / 100000000;
		uint32		value2 = (uint32) (value - 100000000 * q);
		const uint32 c = value2 % 10000;
		const uint32 d = value2 / 10000;
		const uint32 c0 = (c % 100) << 1;
		const uint32 c1 = (c / 100) << 1;
		const uint32 d0 = (d % 100) << 1;
		const uint32 d1 = (d / 100) << 1;
		char	   *pos = a + olength - i;
		value = q;
		memcpy(pos - 2, DIGIT_TABLE + c0, 2);
		memcpy(pos - 4, DIGIT_TABLE + c1, 2);
		memcpy(pos - 6, DIGIT_TABLE + d0, 2);
		memcpy(pos - 8, DIGIT_TABLE + d1, 2);
		i += 8;
	}
	value2 = (uint32) value;
	if (value2 >= 10000)
	{
		const uint32 c = value2 - 10000 * (value2 / 10000);
		const uint32 c0 = (c % 100) << 1;
		const uint32 c1 = (c / 100) << 1;
		char	   *pos = a + olength - i;
		value2 /= 10000;
		memcpy(pos - 2, DIGIT_TABLE + c0, 2);
		memcpy(pos - 4, DIGIT_TABLE + c1, 2);
		i += 4;
	}
	if (value2 >= 100)
	{
		const uint32 c = (value2 % 100) << 1;
		char	   *pos = a + olength - i;
		value2 /= 100;
		memcpy(pos - 2, DIGIT_TABLE + c, 2);
		i += 2;
	}
	if (value2 >= 10)
	{
		const uint32 c = value2 << 1;
		char	   *pos = a + olength - i;
		memcpy(pos - 2, DIGIT_TABLE + c, 2);
	}
	else
		*a = (char) ('0' + value2);
	return olength;
}
int pg_ulltoa_n ( uint64 value , char * a ) { int olength , i = 0 ; uint32 value2 ; if ( value == 0 ) { * a = ' ' ; return 1 ; } olength = decimalLength64 ( value ) ; while ( value >= 100000000 ) { const uint64 q = value / 100000000 ; uint32 value2 = ( uint32 ) ( value - 100000000 * q ) ; const uint32 c = value2 % 10000 ; const uint32 d = value2 / 10000 ; const uint32 c0 = ( c % 100 ) << 1 ; const uint32 c1 = ( c / 100 ) << 1 ; const uint32 d0 = ( d % 100 ) << 1 ; const uint32 d1 = ( d / 100 ) << 1 ; char * pos = a + olength - i ; value = q ; memcpy ( pos - 2 , DIGIT_TABLE + c0 , 2 ) ; memcpy ( pos - 4 , DIGIT_TABLE + c1 , 2 ) ; memcpy ( pos - 6 , DIGIT_TABLE + d0 , 2 ) ; memcpy ( pos - 8 , DIGIT_TABLE + d1 , 2 ) ; i += 8 ; } value2 = ( uint32 ) value ; if ( value2 >= 10000 ) { const uint32 c = value2 - 10000 * ( value2 / 10000 ) ; const uint32 c0 = ( c % 100 ) << 1 ; const uint32 c1 = ( c / 100 ) << 1 ; char * pos = a + olength - i ; value2 /= 10000 ; memcpy ( pos - 2 , DIGIT_TABLE + c0 , 2 ) ; memcpy ( pos - 4 , DIGIT_TABLE + c1 , 2 ) ; i += 4 ; } if ( value2 >= 100 ) { const uint32 c = ( value2 % 100 ) << 1 ; char * pos = a + olength - i ; value2 /= 100 ; memcpy ( pos - 2 , DIGIT_TABLE + c , 2 ) ; i += 2 ; } if ( value2 >= 10 ) { const uint32 c = value2 << 1 ; char * pos = a + olength - i ; memcpy ( pos - 2 , DIGIT_TABLE + c , 2 ) ; } else * a = ( char ) ( ' ' + value2 ) ; return olength ; }
Get the decimal representation, not NUL-terminated, and return the length of
 same.
Get the decimal representation not NUL - terminated and return the length of same .
/* Degenerate case */ /* Compute the result string. */ /* Switch to 32-bit for speed */