|
Prev: mismatch between Perl 5.6 and Perl 5.8 in printing high precision values.
Next: mismatch between Perl 5.6 and Perl 5.8 in printing high precision values.
From: Mirco Wahab on 2 Apr 2008 10:25 sisyphus wrote: > On Apr 2, 9:21 pm, vivekanand.n...(a)gmail.com wrote: >> printf("%.32g\n",0.99999999976716936); >> Perl 5.6.1 output: >> 0.99999999976716936 --> GOOD >> Perl 5.8.6 output: >> 0.99999999976716925 --> ERROR > I believe it's a bug in perl 5.8 (which has been carried through to > perl 5.10): > C:\_32\pscrpt>perl -e "printf(\"%.32g\n\",0.99999999976716936);" > 0.99999999976716925 > C:\_32\pscrpt>perl -e "printf(\"%.32g\n\",9.9999999976716936e-1);" > 0.99999999976716936 > > Since 0.99999999976716936 == 9.9999999976716936e-1, I can think of no > good reason that that those 2 one-liners should produce different > output - and I believe the first one liner produces an incorrect > result. > > I'll submit a bug report about this - unless someone can convince me > that it's *not* a bug (or unless someone else wants to submit the > report). Seems to be dependend on the underlying C library implementation. Consider the following program round.c: ----- [round.c] ----- #include "stdio.h" int main() { printf("0.99999999976716936\n"); printf("%.32g | %.36f\n", 0.99999999976716936, 0.99999999976716936); printf("%.32g | %.36f (%s)\n",9.9999999976716936e-1,9.9999999976716936e-1,"sisyphus"); return 0; } -------------------- Results: ========= Linux/gcc: gcc-4.3 -o round round.c ; ./round 0.99999999976716936 0.99999999976716935634613037109375 | 0.999999999767169356346130371093750000 0.99999999976716935634613037109375 | 0.999999999767169356346130371093750000 (sisyphus) WinXP/Visual-C++ 2005 & Visual C++6.0 (same results): 0.99999999976716936 0.99999999976716936 | 0.999999999767169360000000000000000000 0.99999999976716936 | 0.999999999767169360000000000000000000 (sisyphus) WinXP/MinGW 3.4.2 0.99999999976716936 0.99999999976716936 | 0.999999999767169360000000000000000000 0.99999999976716936 | 0.999999999767169360000000000000000000 (sisyphus) Regards M. |