Mail Archives: djgpp/1996/11/30/08:16:55
afonso AT inesca DOT inesca DOT pt wrote:
>
> Problems with DJGPP V2.01 - atof() function
>
> Hi!
>
> Recently I've made an upgrade of my application from V1.xx
> to V2.01 of DJGPP. In V1.xx my application is working properly.
> After all the corrections I made in source files, due to
> the changes in DJGPP Include files, I finally obtained an
> executable file. But, when I tried to execute it, I got a crash
> of my application! I made a debug and I found the cause of my
> crash that is an incorrect return of atof() function. I'm using
> it as in the example below:
>
> char string[]="1.13";
> int result;
> ...
> result = (int)(atof(string)*100);
> ...
>
> I've got result = 112!!! not 113 as I wished, because
> the function atof() return is 1.29999... not 1.13 (and I only have
> an old i386).
> I think that problem is a bug of DJGPP Library V2.xx.
Not in the library but in the compiler (I'd say)
To work around, just do:
char string[]="1.13";
float f;
int result;
...
f = (int)(atof(string)*100);
result= (int) f;
result should now be 113...
Francois
- Raw text -