I guess the "general rule with floats" is "Never use = or equivalence to compare them. Only use > or < or check within a tolerance".<br><br><div>- Darius</div><br><div class="gmail_quote">On Mon, May 7, 2012 at 8:16 AM, Chris Muller <span dir="ltr"><<a href="mailto:ma.chris.m@gmail.com" target="_blank">ma.chris.m@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok, thanks Darius (and Levente). At first I thought we had a<br>
regression but it looks like we don't.. :)<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Mon, May 7, 2012 at 12:51 AM, Darius Clarke <<a href="mailto:socinian@gmail.com">socinian@gmail.com</a>> wrote:<br>
> I don't believe roundTo: is the method you're looking for.<br>
> I've been confused by this before.<br>
><br>
> roundTo: quantum<br>
> "Answer the nearest number that is a multiple of quantum."<br>
><br>
> ^(self / quantum) rounded * quantum<br>
><br>
> Maybe try this:<br>
><br>
> roundedToFloat: quantum<br>
> "Round to decimal places."<br>
> | aReciprocal |<br>
> aReciprocal := quantum reciprocal rounded.<br>
><br>
> ^(self * aReciprocal) rounded / aReciprocal asFloat<br>
><br>
><br>
><br>
> On Sun, May 6, 2012 at 9:20 PM, Levente Uzonyi <<a href="mailto:leves@elte.hu">leves@elte.hu</a>> wrote:<br>
>><br>
>> On Sun, 6 May 2012, Chris Muller wrote:<br>
>><br>
>>> ( 0.9580000000000001 roundTo: 0.0001) = 0.9580 "false"<br>
>><br>
>><br>
>> Still didn't look at the code, but 0.0001 is also a Float and it doesn't<br>
>> have an exact representation in base 2. The following works as expected:<br>
>> (0.9580000000000001 roundTo: 0.0001s4) "0.9580s4"<br>
>> (0.9580000000000001 roundTo: 1/10000) "(479/500)"<br>
>><br>
>><br>
>> Levente<br>
>><br>
>>><br>
>>><br>
>>><br>
>>> On Sun, May 6, 2012 at 8:55 PM, Levente Uzonyi <<a href="mailto:leves@elte.hu">leves@elte.hu</a>> wrote:<br>
>>>><br>
>>>> On Sun, 6 May 2012, Chris Muller wrote:<br>
>>>><br>
>>>>> With the latest trunk updates, I'm having trouble rounding to my<br>
>>>>> desired precision:<br>
>>>>><br>
>>>>> 0.9580000000000001 roundTo: 0.0001 " 0.9580000000000001"<br>
>>>>><br>
>>>>> In Squeak 4.3 I get what I expect:<br>
>>>>><br>
>>>>> 0.9580000000000001 roundTo: 0.0001 " 0.958"<br>
>>>>><br>
>>>>><br>
>>>><br>
>>>> I'm pretty sure it's just a difference in printing. 0.958 is unlikely to<br>
>>>> have an exact base 2 representation.<br>
>>>><br>
>>>><br>
>>>> Levente<br>
>>>><br>
>>><br>
>><br>
>><br>
>><br>
><br>
</div></div></blockquote></div><br>