Quote:You may also change/add the commented lines below,so that you could support also negative values:
The idea is simply by not touching the great short code CPallini made for positive values and just treat the negative value as positive and multiplying by -1 at the end to make it negative.
char inputstr = "-.45";
float result= 0.0f;
int len = sizeof(inputstr)-1;
if (inputstr=='-'||inputstr=='+') n=1; else n=0;
for (; n < len; ++n) if (inputstr[n] == '.')
dotpos = len - n - 1;
result = result * 10.0f + (inputstr[n]-'0');
result /= 10.0f;
if (inputstr=='-') result*=(-1); printf("%f\n",result);
I have changed size_t to integer,because I don't know how to use them.