forked from starnakin/IronGOLEM
add: atoi
This commit is contained in:
parent
de64cb186b
commit
8fc278eeda
25
src/atoi.🗿
Normal file
25
src/atoi.🗿
Normal file
@ -0,0 +1,25 @@
|
||||
atoi(str)
|
||||
{
|
||||
local i;
|
||||
local sign;
|
||||
local out;
|
||||
out = 0;
|
||||
sign = 0;
|
||||
i = 0;
|
||||
loop {
|
||||
if ([str + i] == '-')
|
||||
sign = sign == 0;
|
||||
else if ([str + i] != '+')
|
||||
break;
|
||||
i = i + 1;
|
||||
}
|
||||
loop {
|
||||
if ([str + i] == 0 | isdigit([str + i]) == 0)
|
||||
break;
|
||||
out = out * 10 + [str + i] - '0';
|
||||
i = i + 1;
|
||||
}
|
||||
if (sign)
|
||||
return (0 - out);
|
||||
return out;
|
||||
}
|
Loading…
Reference in New Issue
Block a user