From: "rjprado@..." Date: 2007-06-22T05:00:03+09:00 Subject: Re: Ruby doesn't know how to multiply On Jun 21, 3:49 pm, "Adriano Ferreira" wrote: > On 6/21/07, juan pedro meri�o wrote: > > > You are rigth James, but you can better reponse why is a floating point > > error? > > Some numbers (like 0.1) cannot be represented exactly in binary with a > finite number of bits (because 0.1[base 10] = > 0.0001100110011001100110011...[base 2]) and when they are represented > (as it happens with floating point representations), they lose > precision. So you must not test floating point for equality but always > rely on some tolerance and use an expression like MenTaLguY showed: > > ( 14.95 * 0.6 - 8.97 ).abs < tol > > where tol depends on your application. I'm starting to remember something about that on my computer architecture course. But it's something so technical and I'm so used to high level programming, that I couldn't remember...