Fix numberToString for limit cases

This commit is contained in:
Vinnie Falco
2013-07-28 21:03:39 -07:00
parent 81c1360679
commit 6002161b05

View File

@@ -361,18 +361,34 @@ namespace NumberToStringConverters
// pass in a pointer to the END of a buffer..
static char* numberToString (char* t, const int64 n) noexcept
{
*--t = 0;
int64 v = (n >= 0) ? n : -n;
do
if (n > 0)
{
*--t = (char) ('0' + (int) (v % 10));
v /= 10;
*--t = 0;
uint64 v = static_cast <uint64> (n);
} while (v > 0);
do
{
*--t = (char) ('0' + (int) (v % 10));
v /= 10;
}
while (v > 0);
}
else
{
*--t = 0;
uint64 v = ((uint64)(-(n + 1)) + 1);
do
{
*--t = (char) ('0' + (int) (v % 10));
v /= 10;
}
while (v > 0);
if (n < 0)
*--t = '-';
}
return t;
}