|
From: Julian S. <js...@ac...> - 2008-05-06 11:42:20
|
On Tuesday 06 May 2008 13:33, jody wrote: > Hi > I'm using valgrind-3.2.1 on fedora 6. > > I have encounter a situation where computations with doubles > give different result when the application is run normally or under > valgrind. Yes. See http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits, 8th bullet point. J > > > > Here is a very simple application showing the problem, vgt.c: > > #include <stdio.h> > #include <math.h> > > > int main(int argc, char *argv) { > > > double a; > double b; > double c; > FILE *f = fopen("num.dat", "rb"); > fread(&a, sizeof(double), 1, f); > fread(&b, sizeof(double), 1, f); > fread(&c, sizeof(double), 1, f); > fclose(f); > > printf("a:%.20f, b:%.20f, c:%.20f\n", a,b,c); > printf("a-b:%.20f, (a-b)/c:%.20f\n", a-b,(a-b)/c); > double d = (a-b)/c; > printf("%.20f\n", floor(d)); > return 0; > } > > Here is the hexdump of the data file num.dat: > [jody]:~/progs/neander/import:$hexdump -C num.dat > 00000000 a9 9a fe ff ff ff 48 40 00 00 00 00 00 00 2e c0 > |......H@........| 00000010 6b 55 10 11 11 11 a1 3f > |kU.....?| 00000018 > > The normal output: > [jody]:~/progs/neander/import:$./vgt > a:49.99999999935000261075, b:-15.00000000000000000000, > c:0.03333333333300000229 a-b:64.99999999934999550533, > (a-b)/c:1950.00000000000000000000 > 1950.00000000000000000000 > > Output under valgrind: > [jody]:~/progs/neander/import:$valgrind --tool=memcheck ./vgt > ==23277== Memcheck, a memory error detector. > ==23277== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al. > ==23277== Using LibVEX rev 1658, a library for dynamic binary translation. > ==23277== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP. > ==23277== Using valgrind-3.2.1, a dynamic binary instrumentation framework. > ==23277== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al. > ==23277== For more details, rerun with: -v > ==23277== > a:49.99999999935000261075, b:-15.00000000000000000000, > c:0.03333333333300000229 a-b:64.99999999934999550533, > (a-b)/c:1949.99999999999977262632 > 1949.00000000000000000000 > ==23277== > ==23277== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1) > ==23277== malloc/free: in use at exit: 0 bytes in 0 blocks. > ==23277== malloc/free: 1 allocs, 1 frees, 352 bytes allocated. > ==23277== For counts of detected errors, rerun with: -v > ==23277== All heap blocks were freed -- no leaks are possible. > > > It is important that both calculations (normal & valgrind) are the same - > with the faulty calculation my real program never gets to the point i am > interested in. > > Is this a bug or did i overlook something? > > Thanks > jody > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/java >one _______________________________________________ > Valgrind-users mailing list > Val...@li... > https://lists.sourceforge.net/lists/listinfo/valgrind-users |