Mercurial > projects > ldc
view test/bug55.d @ 97:c4e161556a21 trunk
[svn r101] Split up CastExp into several smaller utility functions.
author | lindquist |
---|---|
date | Wed, 14 Nov 2007 20:18:01 +0100 |
parents | 70d6113eeb8c |
children | d9d5d59873d8 |
line wrap: on
line source
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); }