[squeak-dev] Float parsed as a Fraction bug

J. Vuletich (mail lists) juanlists at jvuletich.org
Fri Aug 8 22:52:14 UTC 2014


Hi Levente,

Quoting Levente Uzonyi <leves at elte.hu>:

> On Fri, 8 Aug 2014, J. Vuletich (mail lists) wrote:
>
>> Hi Levente,
>>
>> I just saw your commit to the inbox. I also had fun with this last  
>> night, and the result is attached. I hope you prefer my version. It  
>> is faster and shorter.
>
> It looks pretty cool. I tried to avoid Floats, that's why it's  
> slower, but asymptotically they are the same.

At first sight I thought your version would be much slower. So I  
benchmarked a bit and you are right. The difference is not big.

> I'd rewrite the line
>
>  exponent5 _ (without2Factors highBit / (5 log / 2 log)) rounded.
>
> to
>
>  exponent5 _ (0.43067655807339306 "2 ln / 5 ln" * without2Factors  
> highBit) truncated.

Thanks. I adopted this.

> I didn't think too much about why #truncated is enough, but it seems  
> like it is.

Well, it is because #highBit gives log2 not of our number, but of the  
next bigger power of two. So #truncated is ok.

> Also, I'm not sure if #storeOn: has to use the literal form. In  
> Squeak the debugger uses #printOn: during decompilation.

At least on Cuis, for any object, #printOn: gives a 'human readable  
form' and #storeOn: gives a compilable expression. So, for  
decompilation, #storeOn: is used. Having separate methods for these  
features is a good thing. For instance, after these changes, (3/4)  
still prints as (3/4) in Cuis. The literal form is used in  
decompilation, and the way to compile that Fraction literal in the  
first place must have been using this syntax. Therefore there are no  
new annoyances because of this changes.

I don't know when Cuis and Squeak diverged on this, but the comments  
in Object>>printOn: and Object>>storeOn: in Cuis suggest this  
behavior, and the method timestamps are older than Cuis itself...

Cheers,
Juan Vuletich

> Levente
>
>>
>> It could also make it easier to do the computation just once  
>> instead of twice (with further refactoring to #isLiteral and  
>> #storeOn:).
>>
>> Cheers,
>> Juan Vuletich
>>
>> Quoting "J. Vuletich (mail lists)" <juanlists at jvuletich.org>:
>>
>>> Quoting Levente Uzonyi <leves at elte.hu>:
>>>
>>>>
>>>> Try debugging the following snippet:
>>>>
>>>> | x |
>>>> x := 5e-1.
>>>> x := x + 1
>>>>
>>>> You'll find that in Cuis it'll be decomipled as:
>>>>
>>>> DoIt
>>>> 	| x |
>>>> 	x _ (1/2).
>>>> 	^ x _ x + 1.
>>>>
>>>> And the debugger will get confused (in Squeak and Pharo too),  
>>>> because there's (1/2) instead of 5e-1, which is not a literal.
>>>> Also if you press Over, then Proceed in the debugger, then the  
>>>> image will become unresponsive in Cuis (Cuis4.2-1766).
>>>
>>> Thanks, Levente. This is what I needed.
>>>
>>> The debugger becoming unresponsive is an unrelated bug, I just fixed it.
>>>
>>> The debugger printing the fraction as a division is a rather minor  
>>> annoyance, not bad enough for giving up the cool '5e-1' syntax, in  
>>> my opinion. But given that the parser can understand '5e-1', the  
>>> fraction should be able to print as a literal. Looks like I'm  
>>> having some numerics fun tonight :)
>>>
>>>> Levente
>>>>
>>>>>
>>>>>> --
>>>>>> best,
>>>>>> Eliot
>>>
>>> Cheers,
>>> Juan Vuletich
>>
>>





More information about the Squeak-dev mailing list