Mercurial > projects > ldc
comparison tests/mini/bug55.d @ 341:1bb99290e03a trunk
[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.
author | lindquist |
---|---|
date | Sun, 13 Jul 2008 02:51:19 +0200 |
parents | test/bug55.d@d9d5d59873d8 |
children |
comparison
equal
deleted
inserted
replaced
340:351c0077d0b3 | 341:1bb99290e03a |
---|---|
1 module bug55; | |
2 extern(C) int printf(char*, ...); | |
3 | |
4 int atoi(char[] s) { | |
5 int i, fac=1; | |
6 bool neg = (s.length) && (s[0] == '-'); | |
7 char[] a = neg ? s[1..$] : s; | |
8 foreach_reverse(c; a) { | |
9 i += (c-'0') * fac; | |
10 fac *= 10; | |
11 } | |
12 return !neg ? i : -i; | |
13 } | |
14 | |
15 void main() | |
16 { | |
17 printf("64213 = %d\n", atoi("64213")); | |
18 printf("-64213 = %d\n", atoi("-64213")); | |
19 assert(atoi("64213") == 64213); | |
20 assert(atoi("-64213") == -64213); | |
21 } |