If you add these two lines:
my $x = $final_data{$key};
printf "x = %.20f high= %.20f\n", $x, $high;
you will get this output:
x = 0.98999999999999999000 high= 0.99000000000000010000
x = 0.97999999999999998000 high= 0.98000000000000009000
x = 0.96999999999999997000 high= 0.97000000000000008000
x = 0.95999999999999996000 high= 0.96000000000000008000
x = 0.94999999999999996000 high= 0.95000000000000007000
x = 0.93999999999999995000 high= 0.94000000000000006000
x = 0.93000000000000005000 high= 0.94000000000000006000
x = 0.92000000000000004000 high= 0.93000000000000005000
x = 0.91000000000000003000 high= 0.92000000000000004000
x = 0.90000000000000002000 high= 0.91000000000000003000
As you can see, the 0.99 that you get by assigning 0.99 is not the same as the 0.99 you get when you start with 0.90 and add 0.01 nine times. That's the way it is with binary floating point numbers. They're not exactly what you expect. There are several things you could do:
- Don't worry about it. If these are measurements, e.g., then ones that fall right on the boundaries of the bins are inherently ambiguous.
- Use an arbitrary-precision math package. There are ones for Perl, but I haven't used them, so I can't comment more.
- Scale everything so that they are all integers.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.