X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=device%2Flib%2F_atof.c;h=0b897cbe29cd69fed79bc89584b44651ec722f73;hb=51a457fd02440788eaf3f1266e1f80b9a51cfc32;hp=ee7ff24be1ebb36ee6cbeda4706055ff2dda0d22;hpb=ccc1ef43069661e6161d4871d4a44031bd133eb3;p=fw%2Fsdcc diff --git a/device/lib/_atof.c b/device/lib/_atof.c index ee7ff24b..0b897cbe 100644 --- a/device/lib/_atof.c +++ b/device/lib/_atof.c @@ -1,6 +1,6 @@ /* atof.c: converts an ASCII string to float - Copyright (C) 2003 Jesus Calvino-Fraga, jesusc@ieee.org + Copyright (C) 2003 Jesus Calvino-Fraga, jesusc@ieee.org This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,16 +18,13 @@ #include #include +#include float atof(char * s) { float value, fraction; char iexp; -#ifdef SDCC_mcs51 - bit sign; -#else - char sign; -#endif + BOOL sign; //Skip leading blanks while (isspace(*s)) s++; @@ -51,13 +48,13 @@ float atof(char * s) } //Get the fraction - if (*s=='.') + if (*s == '.') { s++; - for (fraction=10.0; isdigit(*s); s++) + for (fraction=0.1; isdigit(*s); s++) { - value+=(*s-'0')/fraction; - fraction*=10.0; + value+=(*s-'0')*fraction; + fraction*=0.1; } } @@ -65,14 +62,13 @@ float atof(char * s) if (toupper(*s)=='E') { s++; - while(*s=='0') s++;//So atoi doesn't return an octal number iexp=(char)atoi(s); { while(iexp!=0) { if(iexp<0) { - value/=10.0; + value*=0.1; iexp++; } else