Dear Monks,

I have two arrays of floating point numbers. One (@nums) contains the full-length version of these numbers. The other (@short_nums) contains these same numbers shortened to 10 deciimal places.

All i am trying to do is find the full-length numbers of a selection of short numbers that are held in a third array (@found).

e.g. @nums = ('0.0989999999999', '0.6799999999999', '0.0859999999999', '0.0 +239999999999'); @short_nums = ('0.099', '0.68', '0.086', '0.024'); @found = ('0.099', '0.086'); if (defined ($found[0])) { for (my $i =0; $i<@short_nums; $i++) { if ($found[0] == $short_nums[$i]) { push @new_array, $nums[$i]; } } } # etc ....
The problem is that sometimes more than one copy of the numbr is pushed into the array (e.g if two matching numbers in @nums are very similar like 0.005000000000007 and 0.005000000000008).

How can I ensure only one copy of each matching number is pushed into @new_array?? Thanks x


In reply to testing for numerical equality by Anonymous Monk

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.