Re: [xml] Getting crazy with float parsing



On Sun, May 05, 2002 at 01:34:15PM -0400, Daniel Veillard wrote:
 I have spent 2 hours on bug 80798
   http://bugzilla.gnome.org/show_bug.cgi?id=80798

 and I'm starting to wonder if I'm simply turning crazy.
I cannot get xmlXPatythStringEvalNumber to read "39413.80" as such
and not as 39413.800000000003 or some similary biased value, whatever
trick I play. 
 Any idea ? Would trio handle this correctly (assuming the string has
been first checked to be of the right format) ?

I think this is just because of the inherent inaccuracy of floating point
numbers:

~$ cat test.c 
#include <stdio.h>

int main(void)
{
    double d = 39413.8;
    printf("%.20f\n", d);
    return(0);
}

~$ gcc test.c -o test
~$ ./test 
39413.80000000000291038305
~$

I don't think there's any way of getting a double to equal exactly
39413.80, because the number is stored in base 2, and 0.8 = 4/5 cannot be
represented as an exact fraction in base 2, just as you can't represent 1/3
= 0.3333... as an exact fraction in base 10...

HTH,

Anthony



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