Jason G. wrote:
> Hi
> 
> I wrote a simple test program, basically the program asks the user to
> enter floats. the entered values shall be used as keys for Hash (the
> values are irrelavent).
> 
> The program tries to find the lowest untaken key/float (floats are used
> as keys).
> 
> please see attachment.
> 
> please run the prog, and enter the following:
> 0.01 - OK
> 0.02 - OK
> 0.03 - OK
> 0.04 - OK
> 0.05 - OK
> 0.06 - Problem
> 
> Can anyone explain to me what's going on here?
> 

You should never compare floating point numbers for equality in any 
language. This is true at least for C, C++, .NET, and Java, to name a 
few. It just won't be accurate. Unlike integers, floats are not stored 
as their true Platonic forms ;). If you really wanted to see how the 
digits differed, you could print both numbers to a large number of 
digits (printf("%.20f", my_number)). You don't even need to do any math 
to see the roundoff error.

 >> printf("%.50f", 1.1)
1.10000000000000008881784197001252323389053344726562

To compare floats, you must ask whether they are within a certain 
threshold of each other.
Epsilon = 0.00000000001
return (num1-num2).abs < Epsilon # num1 == num2

Dan