Mercurial > projects > ldc
comparison 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 |
comparison
equal
deleted
inserted
replaced
91:3f949c6e2e9d | 92:70d6113eeb8c |
---|---|
1 module bug55; | |
2 | |
3 int atoi(char[] s) { | |
4 int i, fac=1; | |
5 bool neg = (s.length) && (s[0] == '-'); | |
6 char[] a = neg ? s[1..$] : s; | |
7 foreach_reverse(c; a) { | |
8 i += (c-'0') * fac; | |
9 fac *= 10; | |
10 } | |
11 return !neg ? i : -i; | |
12 } | |
13 | |
14 void main() | |
15 { | |
16 printf("64213 = %d\n", atoi("64213")); | |
17 printf("-64213 = %d\n", atoi("-64213")); | |
18 assert(atoi("64213") == 64213); | |
19 assert(atoi("-64213") == -64213); | |
20 } |