Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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).
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).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 ....
How can I ensure only one copy of each matching number is pushed into @new_array?? Thanks x
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: testing for numerical equality
by Zaxo (Archbishop) on Jul 14, 2003 at 11:15 UTC | |
|
Re: testing for numerical equality
by choocroot (Friar) on Jul 14, 2003 at 11:32 UTC | |
|
Re: testing for numerical equality
by aquarium (Curate) on Jul 14, 2003 at 11:05 UTC | |
by Abigail-II (Bishop) on Jul 14, 2003 at 11:12 UTC | |
|
Re: testing for numerical equality
by sgifford (Prior) on Jul 14, 2003 at 16:37 UTC |