Mercurial > projects > ldc
diff test/bug55.d @ 92:70d6113eeb8c trunk
[svn r96] Updated to DMD 1.023.
Regular bugfixes.
author | lindquist |
---|---|
date | Thu, 08 Nov 2007 19:13:28 +0100 |
parents | |
children | d9d5d59873d8 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug55.d Thu Nov 08 19:13:28 2007 +0100 @@ -0,0 +1,20 @@ +module bug55; + +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); +}