Files
ldc/test/bug55.d
Tomas Lindquist Olsen 964f91b5a1 [svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
Branch statements now emit a new block after it.
Fixed the _adSort runtime function had a bad signature.
Added a missing dot prefix on compiler generated string tables for string switch.
Fixed, PTRSIZE seems like it was wrong on 64bit, now it definitely gets set properly.
2008-06-16 16:01:19 +02:00

22 lines
454 B
D

module bug55;
extern(C) int printf(char*, ...);
int atoi(char[] s) {
int i, fac=1;
bool neg = (s.length) && (s[0] == '-');
char[] a = neg ? s[1..$] : s;
foreach_reverse(c; a) {
i += (c-'0') * fac;
fac *= 10;
}
return !neg ? i : -i;
}
void main()
{
printf("64213 = %d\n", atoi("64213"));
printf("-64213 = %d\n", atoi("-64213"));
assert(atoi("64213") == 64213);
assert(atoi("-64213") == -64213);
}