Re: glib 2.2.3 test failures on Solaris



On Mon, 2003-09-15 at 10:37, Alexander Larsson wrote:
> On Sun, 2003-09-14 at 00:00, Albert Chin wrote:
> > I'm getting a test failure in strtod-test on glib-2.2.3 on Solaris
> > 2.5.1-9/SPARC with Sun's C compiler, HP-UX 11.00 with the HP C
> > compiler, and AIX 5.1 with the IBM C compiler. The problem is:
> > 
> >   d = pow (2.0, -1024.1);
> >   g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
> > 
> > If I:
> >   g_ascii_dtostr (buffer, sizeof (buffer), d);
> >   printf ("%s\n", buffer);
> >   printf ("%f %f %f\n", d, strtod (buffer, NULL),
> >           g_ascii_strtod (buffer, NULL));
> > I get:
> >   5.1901682964836177e-309
> >   0.000000 0.000000 0.000000
> 
> You have to use %g to get anything other that 0.0 for these values,
> since we're operating on the edges of double precision here. It is
> entierly possible that the precision of the built-in strtod in the other
> systems just isn't high enough to make the assert work.
> 
> >   (Redhat Linux 9 gives)
> >     5.1901682964836274e-309
> >     0.000000 0.000000 -1.231230
> 
> This however, is a bit strange. It should give three zeros.
> I did some testing, showing up some very very strange behaviour:
> 
>  d = pow (2.0, -1024.1);
>  g_ascii_dtostr (buffer, sizeof (buffer), d);
>  g_print ("buffer: %s\n", buffer);
>  g_print ("strtod(buffer) == %g\n", strtod (buffer, NULL));
>  g_print ("buffer2: %s\n", buffer);
>  g_print ("g_ascii_strtod(buffer) == %g\n", g_ascii_strtod (buffer, NULL));
>  g_print ("strtod(buffer) == %g\n", strtod (buffer, NULL));
> 
> On RH9 this prints out:
> 
> buffer: 5.1901682964836274e-309
> strtod(buffer) == 1.9036e+185
> buffer2: 5.1901682964836274e-309
> g_ascii_strtod(buffer) == 5.19017e-309
> strtod(buffer) == 5.19017e-309
> 
> WTF!!!?!
> 
> Why does the first call to strtod seemingly ignore the initial 5, and
> make the exponent all wrong, but the second call does the right thing?

It works better if you include stdlib.h. /me hangs head in shame.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's an all-American neurotic vagrant from a doomed world. She's a provocative 
belly-dancing fairy princess from the wrong side of the tracks. They fight 
crime! 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]