[Pharo-dev] float & fraction equality bug
Nicolas Cellier
nicolas.cellier.aka.nice at gmail.com
Thu Nov 9 12:20:56 EST 2017
2017-11-09 18:11 GMT+01:00 Raffaello Giulietti <
raffaello.giulietti at lifeware.ch>:
> 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
>
>
> You are violating the invariants described in class comment in this case,
and thus missusing Fraction.
So it's not anymore the problem of the library
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20171109/7452f709/attachment-0002.html>
More information about the Pharo-dev
mailing list