in reply to Problems with defining hashes

You're using floating point numbers as keys in the hash and this is probably something that you shouldn't do, unless you exactly know what you're doing.

Consider that 5.0, 5.5 and 0.1 have not an exact representation inside the computer, due to its binary nature and finite bits per number; given the fact that your cycles start from different starting points (5.0 the first, 5.5 the second), you end up having slightly different number in $mag in the first and second loop, i.e. different keys in the hash.

I would suggest that you fix the magnitudes somewhere (an array, for example), then use some integer index just to be sure not to mess things up.

Flavio

Don't fool yourself.

Replies are listed 'Best First'.
Re^2: Problems with defining hashes
by ysth (Canon) on Mar 30, 2005 at 18:47 UTC
    5.0 and 5.5 do have exact representations; 0.1 does not.
      Touché :-) Another case of "negative laziness"...

      Flavio

      Don't fool yourself.
Re^2: Problems with defining hashes
by Annemarie (Acolyte) on Mar 30, 2005 at 23:27 UTC
    Thanks, Falvio. I had completely forgotten about the issues with using floating point numbers.