bug in atof

Peter Beutner p.beutner at gmx.net
Sat Jan 21 09:29:11 CST 2006

Uwe Bonnes schrieb:
>>>>>> "Louis" == Louis Lenders <xerox_xerox2000 at yahoo.co.uk> writes:
>     Louis> Hi, i filed a bug ( bug 4337) and looks like there's a bug in
>     Louis> atof. Is there a difference between linux' atof and msvcrt's one?
>     Louis> Even following simple program (from msdn) yields wrong results:
>     Louis> // crt_atof.c #include <stdlib.h> #include <stdio.h>
>     Louis> int main( void ) { char *s; double x; int i; long l;
>     Louis>    s = " -2309.12E-15"; /* Test of atof */ x = atof( s ); printf(
>     Louis> "atof test: \"%s\"; float: %e\n", s, x );
>     Louis>    s = "7.8912654773d210"; /* Test of atof */ x = atof( s );
>     Louis> printf( "atof test: \"%s\"; float: %e\n", s, x );
>     Louis>    s = " -9885 pigs"; /* Test of atoi */ i = atoi( s ); printf(
>     Louis> "atoi test: \"%s\"; integer: %d\n", s, i );
>     Louis>    s = "98854 dollars"; /* Test of atol */ l = atol( s ); printf(
>     Louis> "atol test: \"%s\"; long: %ld\n", s, l ); } the exponent value in
>     Louis> float x are wrong. Thanks
> Not atof() is the cause of your bug, but printf(). 
> I entered your sample into the test suite to show the correct behaviour of
> wine's implementation of atof. The printf() test has already a todo for the
> incorrect exponent output.

quoted from msdn[1]:
The string argument to atof and _wtof has the following form:

[whitespace] [sign] [digits] [.digits] [ {d | D | e | E }[sign]digits

Which means that '7.8912654773d210' is the same as '7.8912654773e210'.

But on linux we have(quoted from 'man strtod'):
A decimal number consists of a nonempty sequence of decimal digits pos-
sibly  containing  a  radix character (decimal point, locale dependent,
usually ``.''), optionally followed by a decimal exponent.   A  decimal
exponent consists of an ``E'' or ``e'', followed by an optional plus or
minus sign, followed by a non-empty sequence  of  decimal  digits,  and
indicates multiplication by a power of 10.

It doesn't parse 'd' or 'D' as exponent.
Seems to be a "MS-only extension" to the standard :p


More information about the wine-devel mailing list