[Pharo-dev] float & fraction equality bug
Raffaello Giulietti
raffaello.giulietti at lifeware.ch
Thu Nov 9 12:11:32 EST 2017
On 2017-11-09 15:55, Nicolas Cellier wrote:
>
>
> 2017-11-09 15:48 GMT+01:00 Tudor Girba <tudor at tudorgirba.com
> <mailto:tudor at tudorgirba.com>>:
>
> Hi,
>
> Thanks for the answer. The example I provided was for convenience.
>
> I still do not understand why it is wrong to expect 0.1 = (1/10) to
> be true.
>
> Doru
>
>
> Because there are infinitely many different Fraction that would be
> "equal" to 0.1 then.
> The first effect is that you have
>
> a = b
> a = c
> b < c
>
> You are breaking the fact that you can sort these Numbers (are they
> Magnitude anymore?)
> You are breaking the fact that you can mix these Numbers as Dictionary
> keys (sometimes the dictionary would have 2 elements, sometimes 3,
> unpredictably).
>
>
Fractions are not reliable keys anyway:
(Fraction numerator: 1 denominator: 3) = (Fraction numerator: 2
denominator: 6)
evaluates to true while
(Fraction numerator: 1 denominator: 3) hash = (Fraction numerator: 2
denominator: 6) hash
evaluates to false
More information about the Pharo-dev
mailing list