Or just use ScaledDecimal instead of Float

0.5 asScaledDecimal * 0.5 asScaledDecimal = (1/2 * (1/2)) true
0.5 asScaledDecimal / 3 = (1/2 * (1/3)) true


2014-05-20 19:21 GMT-03:00 Nicolas Cellier <
[email protected]>:

>
> 2014-05-21 0:16 GMT+02:00 Eliot Miranda <[email protected]>:
>
>
>>
>>
>> On Tue, May 20, 2014 at 1:45 PM, Sean P. DeNigris 
>> <[email protected]>wrote:
>>
>>> Maximiliano Taborda wrote
>>> > Seeing the same with aconcagua
>>> > ...
>>> >  teaspoons := BaseUnit named: 'teaspoons'.
>>> >  aHalfTeaspoon := Measure amount: 1/2 unit: teaspoons.
>>> >  anotherHalfTeaspoon := Measure amount: 0.5 unit: teaspoons.
>>> >
>>> > "#hash"
>>> >  aHalfTeaspoon hash = anotherHalfTeaspoon hash "this evaluate to true"
>>> >
>>> > So, I don't see where is the bug.
>>>
>>> It seems to only appear when comparing measures with derived units...
>>>
>>> baseUnit := BaseUnit named: 'tablespoon'.
>>> unit := ProportionalDerivedUnit baseUnit: baseUnit conversionFactor: 1/3
>>> named: 'teaspoon'.
>>> m1 := Measure amount: 1/2 unit: unit.
>>> m2 := Measure amount: 0.5 unit: unit.
>>> m1 hash = m2 hash. "this evaluate to false"
>>>
>>
>>
>> are you surprised?
>>
>> 0.5 * 0.5 = (1/2 * (1/2)) true
>> 0.5 / 3 = (1/2 * (1/3)) false
>>
>> You can't divide floats by 3 and get an exact answer:
>>
>> 0.5 / 3 = 0.16666666666666666
>>
>> (1/2)/3 = (1/6)
>>
>
> Good find!
> Use a smaller spoon, like 1/4 ;)
>
>
>>
>>
>>>
>>>
>>> -----
>>> Cheers,
>>> Sean
>>> --
>>> View this message in context:
>>> http://forum.world.st/Aconcagua-Hashing-Bug-tp4759622p4759745.html
>>> Sent from the Pharo Smalltalk Developers mailing list archive at
>>> Nabble.com.
>>>
>>>
>>
>>
>> --
>> best,
>> Eliot
>>
>
>

Reply via email to