[squeak-dev] Float parsed as a Fraction bug

Eliot Miranda eliot.miranda at gmail.com
Thu Aug 7 18:58:39 UTC 2014


Hi Levente,


On Thu, Aug 7, 2014 at 11:47 AM, Levente Uzonyi <leves at elte.hu> wrote:

> On Thu, 7 Aug 2014, Eliot Miranda wrote:
>
>  Hi Juan,
>>
>> On Thu, Aug 7, 2014 at 9:40 AM, J. Vuletich (mail lists) <
>> juanlists at jvuletich.org> wrote:
>>
>>       Hi Folks,
>>
>>       Just tried Smalltalk-80 (actually Apple Smalltalk-80 running in
>> Mini vMac).
>>       1e-3 "printIt" (1/1000)
>>       1e-3 class "printIt" Fraction
>>       1e3 "printIt" 1000
>>       1e3 class "printIt" SmallInteger
>>
>>       This has always been the behavior in Squeak too.
>>
>>
>> What happens if you try compiling a method containing a literal Fraction
>> and both debug it and decompile it.
>>
>>       Also check these comments from Dan: http://lists.squeakfoundation.
>> org/pipermail/squeak-dev/2000-March/013368.html
>>
>>
>> Dan doesn't say anything about Fraction literals in this message.
>>
>
> I guess the key parts are
>
>  Lowercase 'e' is used to designate the exponent of a floating point
>>> number (as are 'd' and 'q').  It is illegal to specify an exponent for
>>> what is otherwise an integer--eg, 10e10 is illegal, while 10.0e10 is
>>> legal.
>>
>>
Right, which I see as orthogonal to the literal Fractions issue.


> and
>
> "Radix, digits and exponent defined analogously over ints, largeInts, and
> Floats."
>
>>
>>       I don't think this is a bug at all.
>>
>> What, that 1e-3 is a Fraction, not a Float?
>>
>
> If 1e-3 is a Float, shouldn't 1e3 be a Float too?


I don't see that follows.  If 1e3 is an Integer, does that imply 1e-3 is a
Fraction?  The point is that 1e-3 can be represented either as a Float or a
Fraction, but that Fraction is not a literal.  So in choosing how it is
represented the choice having the least impact on the language semantics is
as a Float.  At least, for me.

If people feel strongly that Fraction should be literal then let's make it
so.  But so far I'e not seen much passion or any compelling arguments that
we make that choice.  However, compatibility with other dialects, and the
existing definitions of isLiteral imply using Floats not Fractions.
-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20140807/debb92c3/attachment-0001.htm


More information about the Squeak-dev mailing list