mescc: Fix itoa for negative numbers, using workaround.
* module/mes/libc.mes (itoa): Avoid `sign = x < 0;' FIXME, todo. * scaffold/t.c (test): Test it.
This commit is contained in:
parent
fe727301c5
commit
0077c9aed6
|
@ -229,19 +229,19 @@ itoa (int x)
|
|||
p += 9;
|
||||
*p-- = 0;
|
||||
|
||||
//int sign = x < 0;
|
||||
int sign;
|
||||
sign = x < 0;
|
||||
//int sign = x < 0; // FIXME
|
||||
int sign = 0;
|
||||
if (x < 0) sign = 1;
|
||||
if (sign)
|
||||
x = -x;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
*p-- = '0' + (x % 10);
|
||||
x = x / 10;
|
||||
} while (x);
|
||||
|
||||
if (sign)
|
||||
if (sign && *(p + 1) != '0')
|
||||
*p-- = '-';
|
||||
|
||||
return p+1;
|
||||
|
|
12
scaffold/t.c
12
scaffold/t.c
|
@ -895,6 +895,18 @@ test (char *p)
|
|||
puts ("t: itoa (33) == \"33\"\n");
|
||||
if (strcmp (itoa (33), "33")) return 1;
|
||||
|
||||
puts ("strcmp (itoa (-1), \"-1\")\n");
|
||||
if (strcmp (itoa (-1), "-1")) return 1;
|
||||
|
||||
char *fixme_globals;
|
||||
fixme_globals = "0";
|
||||
fixme_globals = "1";
|
||||
puts ("strcmp (itoa (0), \"0\")\n");
|
||||
if (strcmp (itoa (0), "0")) return 1;
|
||||
|
||||
puts ("strcmp (itoa (1), \"1\")\n");
|
||||
if (strcmp (itoa (1), "1")) return 1;
|
||||
|
||||
return struct_test ();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue