From: "Adam Ms." Date: 2012-01-27T00:28:47+09:00 Subject: Re: Microrant on Ruy's Math Skills Gavin Sinclair wrote in post #1042645: > On Thu, Jan 26, 2012 at 7:33 PM, Intransition > wrote: > The current > definition of Float.== is insufficient for its task, and simply > reflects Ruby's C heritage. I wonder if anybody would be put out if > it were redefined to be more useful and less surprising. > > Gavin Well... You lost me here. Why not just say we don't compare floats for equality because the representation of floats in binary is only an approximation. This is the behavior expected by the computer scientist. It is not a language specific issue. This whole thread is based on a faulty premise. For those who have not had the requisite training try it yourself. Define a simple floating point format. Super simple. Let's call it “8.8”. 8 bits of integer part: 0-255 can be represented. (ignore negatives/two's-complement, for this simplistic example). 8 bits of fraction: 1/256ths. Here is the binary representation for the base 10 float 1.25: 0000 0001 0100 0000 The fractional part is 64. 64/256 = 1/4 = 0.25 Second example. 1.1 in binary: 0000 0001 0001 1001 The fractional part adds up to 25 so this is actually 25/256. Our other choice would have been 26/256. Neither of these choices are equal to 1/10. They are just an approximation. Bonus homework: Write pseudo code to display the ascii, human readable, representation of 8.8 -- Posted via http://www.ruby-forum.com/.