Or just use ScaledDecimal instead of Float0.5 asScaledDecimal * 0.5 asScaledDecimal = (1/2 * (1/2)) true0.5 asScaledDecimal / 3 = (1/2 * (1/3)) true2014-05-20 19:21 GMT-03:00 Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com>:2014-05-21 0:16 GMT+02:00 Eliot Miranda <eliot.miranda@gmail.com>:
On Tue, May 20, 2014 at 1:45 PM, Sean P. DeNigris <sean@clipperadams.com> 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)) true0.5 / 3 = (1/2 * (1/3)) falseYou 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