http://qs321.pair.com?node_id=659051


in reply to Find out missing floating value in an array

manimarank:

Here's a hint on how to do it with floats:

Sort the array, then check the intervals (adjacent values in the array). You'll either find the value, or you'll find an interval where it *should* be, but isn't.

Note: Since many floating point values aren't representable in a binary format, you'll want to use the trick of selecting an arbitrary amount of error you'll accept when you try to determine whether two floats match. For example:

#!/usr/bin/perl -w use warnings; use strict; my $epsilon=0.000005; my $desired=1.15; while (<DATA>) { chomp; if (abs($desired - $_) < $epsilon) { print "Match found: $_\n"; } } __DATA__ 1.149 1.1499 1.14999 1.149999 1.1499999 1.14999999 1.149999999
Prints

$ perl 659004.pl Match found: 1.149999 Match found: 1.1499999 Match found: 1.14999999 Match found: 1.149999999
...roboticus