0.06 == 0.06 returns false in Ruby?



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?

thanks
jason

Attachments:
http://www.ruby-forum.com/attachment/193/test.rb

--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: 0.06 == 0.06 returns false in Ruby?
    ... I wrote a simple test program, basically the program asks the user to ... the entered values shall be used as keys for Hash (the ... The program tries to find the lowest untaken key/float (floats are used ... You should never compare floating point numbers for equality in any language. ...
    (comp.lang.ruby)
  • Re: Concatenate float data type
    ... data type and cannot be a key. ... point math and the IEEE Standards. ... When you test floats for equality, ... You need to use an exact numeric type or CHARfor keys. ...
    (comp.databases.ms-sqlserver)
  • Re: Incorrect -0.0.hash - Ruby bug.
    ... Perhaps the inexact nature of Floats means ... ought not to use them as hash keys? ... In my program it's very convenient to use float vectors as keys because ...
    (comp.lang.ruby)
  • Re: Suggestion for an AES Based Hash Function
    ... amateurs posting here seem to favour cyphers, I go for hash functions. ... Rather than trying to use a strong one-way compression function would ... I have used a fixed set of keys in two places. ... preferred to have the first round keys fixed and to start deriving ...
    (sci.crypt)
  • Suggestion for an AES Based Hash Function
    ... amateurs posting here seem to favour cyphers, I go for hash functions. ... Rather than trying to use a strong one-way compression function would ... The round function ... I have used a fixed set of keys in two places. ...
    (sci.crypt)