To look at this more closely I tried:

my $a = -95.3009707988281 ; show($a) ; my $b = -95.1877600585938 ; show($b) ; my $x = ($a + $b) / 2 ; show($x) ; printf "%20.16f\n", $x ; sub show { my ($f) = @_ ; printf "%-18s 0x%04X_%04X_%04X_%04X\n", $f, unpack("n4", pack("d>", +$f)) ; } ;
this gave:
Windows, perl 5.10.0, 32-bit               Linux, perl 5.10.0, 64-bit
-95.3009707988281  0xC057_D343_1B06_8122   -95.3009707988281  0xC057_D343_1B06_8122
-95.1877600585938  0xC057_CC04_42C3_C9F2   -95.1877600585938  0xC057_CC04_42C3_C9F2
-95.244365428711   0xC057_CFA3_AEE5_258A   -95.2443654287109  0xC057_CFA3_AEE5_258A
-95.2443654287109500                       -95.2443654287109496
which shows that the decimal to binary conversion is giving the same result, as is the arithmetic. What is different is the binary to decimal conversion. It would appear that Perl is stringifying to 15 significant decimal digits, discarding any trailing zeros. Other experiments suggest that the library under Windows is returning 17 significant decimal digits, but the library under Linux is returning rather more -- giving a different result when rounded to 15 decimal digits.

Binary/Decimal conversion is a whole lot trickier than it looks. Producing no more than 17 decimal digits is not unreasonable for IEEE 754 double precision floats. On the face of it, however, what we have here is a double rounding under Windows, which I think is incorrect.

Nevertheless, it is "ambitious" to expect any two floating point values to be exactly equal !


In reply to Re: Decimal precision issue: Windows vs. Unix by gone2015
in thread Decimal precision issue: Windows vs. Unix by whakka

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.