Again problem with atof / sscanf / strtof and float's range
Mathias.Krause at de.telex.com
Mathias.Krause at de.telex.com
Fri Dec 8 11:17:29 UTC 2006
So, i think i have to ask again ...
I am running uCLinux (dist 20060803) with kernel 2.4 and it's uClibc
on a Coldfire MCF5272 processor.
this is the problem:
CODE:
float myFloat = 0.0;
char myString[] =
{"9999999999999999999999999999999999999999999999999.9"};
int ret = 0;
ret = sscanf(myString, "%f", &myFloat);
printf("Return: %i\r\n", ret);
printf("Float: %f\r\n", myFloat);
OUTPUT:
Return: 1
Float: -0.000000
So the return value of scanf is 1 which means taht everything went fine.
But
the number in the string is bigger than the maximum float in the system.
So,
i think that sscanf should return an error.
The same problem exists when using atof or strtof.
> > You're test works find for me. scanf, atof, and strtof all convert to
> > inf for me on mipsel, since your value is larger than the max
> > representable by a float. But while the standard guarantees that
strtof
> > will set errno to ERANGE in this case (which I see in my tests), it
does
> > not make such guarantees with either scanf or atof.
in my example the string is NOT converted to inf. And the sscanf function
does NOT return an error. So how can I realize that an error has occured
while scanning the string?
Again, thanks for your help
Mathias
More information about the uClibc
mailing list