[squeak-dev] The Trunk: System-bf.488.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Jul 10 18:22:37 UTC 2012


2012/7/9 Bert Freudenberg <bert at freudenbergs.de>:
>
> On 2012-07-09, at 22:18, Nicolas Cellier wrote:
>
>> 2012/7/9 Bert Freudenberg <bert at freudenbergs.de>:
>>> On 2012-07-09, at 17:57, Chris Muller wrote:
>>>
>>>> Beat me to it but you forgot to update the sends to
>>>> #asStringWithCommasSigned.  It was deprecated because this is the only
>>>> sender and it's an exceptional case to want to print "+" in front.  We
>>>> should use #asStringWithCommasSigned: true.
>>>
>>> Feel free to improve :)
>>>
>>> Another idea would be to tweak roundTo: so the result would print as expected. Any floating point magician out there? ;)
>>>
>>> - Bert -
>>
>> This would be something like:
>>
>> roundToDecimalPlaces: d
>>    ^(self asTrueFraction roundTo: (1/10 raisedTo: d)) asFloat
>>
>> slightly different from Pharo initial proposition
>> http://code.google.com/p/pharo/issues/detail?id=5590
>> round: d
>>    ^((self * (10 raisedTo: d)) rounded / (10 raisedTo: d)) asFloat
>>
>> For example, with receiver 0.995, we have 0.995 < (995/1000) so the former is
>>
>>    (0.995 roundToDecimalPlaces: d) -> 0.99
>>
>> while the later is
>>
>>    (0.995 round: 2) -> 1.0
>
> Ah, I remember that discussion now. That Pharo version is 10x more efficient than the one using asTrueFraction, though. I'd be happy with that I guess.
>

If the purpose is to print, then the printer will use LargeInteger
arithmetic anyway.
So you would pay at most a factor 2x, not a factor 10x.

Nicolas


More information about the Squeak-dev mailing list