in reply to Floating point (in)accuracy: more "interesting" than expected

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

Replies are listed 'Best First'.
Re^2: Floating point (in)accuracy: more "interesting" than expected
by graff (Chancellor) on Dec 11, 2004 at 20:42 UTC
    Good catch! When I added "sort" into the loop over values, the mac/perl-5.8.1 runs came out with the same answer every time.

    But now that leaves me wondering about freebsd/perl-5.8.5 on the i386 and amd64 machines I tried: why would they always give the same answer, if they're supposed to share 5.8.1's non-deterministic hashing method... Could they actually be that much more accurate?

      Well, there are two possibilities i can think of...

      1. Note that the 5.8.2 perldelta indicates some tweaks were made again. I'm not sure what they were, but maybe they reduced some of the percieved randomness of ordering returned by "values" while keeping the security.
      2. It's possible that your deterministic versions of perl were compiled with "USE_HASH_SEED_EXPLICIT" set, or perhaps you have the "PERL_HASH_SEED" enironment variable set. see INSTALL for more info