If you see the code at #hash method for class Measure, your realize that
this class converts the amount of the measure to its base unit and then
sends hash to this converted value. So, for the case where you have 1/2
teaspoon the #hash method, after some conversions, this does:
          (1/2) * (1/3) = (1/6)
then, obtain the hash of the fraction 1/6 => 7.

The same goes for your 0.5 teaspoon. But, because floats are bad guys, this
is what happens:
          0.5 * (1/3) =  0.16666666666666666 (like Eliot shows)
then, obtain the hash for this ugly float => 72362.

Its ok or not, well, thats depends. If you need a more precise number, use
fractions or scaled decimals.




2014-05-20 21:07 GMT-03:00 Maximiliano Taborda <[email protected]>:

> 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