I think the descrepencies you are seeing have nothing to do with floating point accuracy, and everything to do with hash seed randomization.

As I understand it, in older versions of perl, the hashing algorithm was (somewhat) deterministic, making it possible to "predict" things -- which is not so good for security. circa perl 5.8.1, the hasing algorithm was changed so as to be non-deterministic. ie: every time you run your app, you get a slightly different hashing seed

Which means: every time you run your app, even on identicle input, hashes you build will be slightly different, and the order the elements come back (from either keys or values) will be different. So the second time you execute your app, and loop over the output of values and do incrimental floating point calculations -- you are doing slightly different calculations the the first time you executed the app.

I can't confirm any of this, because I don't have access more then one version of perl right now, but i believe that if you use "sort values" instead of "values" you'll get a deterministic result on any version of perl


In reply to Re: Floating point (in)accuracy: more "interesting" than expected by hossman
in thread Floating point (in)accuracy: more "interesting" than expected by graff

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.