From: Sebastian Hungerecker Date: 2008-10-28T02:15:32+09:00 Subject: Re: float equality guille lists wrote: > I'm a bit lost here, shouldn't (0.1) and (1 - 0.9) be equals regarding > the == operator? No. The result of 1 - 0.9 using floating point math is not actually 0.1. In irb it is displayed as 0.1, but that's only because Float#inspect rounds. Using printf you can see that the result of 1-0.9 actually is 0.09999lots: >> printf "%.30f", 1-0.9 0.099999999999999977795539507497 0.1 itself isn't actually 0.1 either - it's 0.100000000000000005551115123126... Because of this you should not check two floats for equality (usually you want to check for a delta or not use floats at all). This is so because of the inherent inaccuracy of floating point maths. See this for more information: http://docs.sun.com/source/806-3568/ncg_goldberg.html HTH, Sebastian -- Jabber: sepp2k@jabber.org ICQ: 205544826