Re: [squeak-dev] Float parsed as a Fraction bug

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Float parsed as a Fraction bug

Eliot Miranda-2



On Thu, Aug 7, 2014 at 9:05 AM, Levente Uzonyi <[hidden email]> wrote:
On Wed, 6 Aug 2014, Eliot Miranda wrote:

Hi Levente,

On Wed, Aug 6, 2014 at 11:43 AM, Levente Uzonyi <[hidden email]> wrote:
      On Wed, 6 Aug 2014, Eliot Miranda wrote:

            Hi All,
                Squeak trunk also suffers from the Float parsed as a Fraction bug:

            1e-8 class Fraction
            1.0e8 class Float


I'm not entirely sure about it being a bug. I've checked Squeak 3.8 (pre-SqNumberParser), and it also parsed that literal as a Fraction. If I want a Float, I can be explicit and use 1.0e-8.


IMO it very much *is* a bug.  Smalltalk-80 has never supported Fraction literals.  They're always written as division expressions.  Fraction answers false to isLiteral.  Just because it worked that way
doesn't mean it was right.  I suspect no one noticed.  Allowing Fraction literals feels like a big change to me.

It's more like undefined behavior than a bug IMHO, though the lack of #isLiteral makes me think that the Fractions are not intentional. Interesting how Nicolas's SqNumberParser behaves the same way as the previous number parser in this case.



      I made a modified version of Fraction >> #printOn:base: which outputs the literal format if possible. The change "fixes" the debugger (note that itw was way less broken in Squeak than in Pharo
      anyway).
      The only drawback I found is that some fractions become a bit more "complex" when printed, e.g. 3/4 => 75e-2


OK, but is this the right fix?  What does everybody think?  Keep the language unchanged or add Fraction literals and add another incompatibility with other dialects?

I don't think that anyone ever used this "feature" before, so doing what other dialects do is probably the best way to resolve this.

Agreed.  Smalltalk-80 v2 had no literal fractions.  ObjectWorks and VisualWorks have never had literal fractions.  I can't speak for other dialects, but I'm fairly sure none of the Smalltalk/V, Team/V lineage had literal Fractions either.

If Fractions are literals
- what is the semantics of 1/0 (easy, it is not a literal, but needs to be stated)?
- what is [1/0.1] on: ZeroDivide do: [:ex| #error] ?  Is it 10.0 or #error, i.e. is 1/0.1 10.0 or 1 / 0 followed by the Integer 1?

I did not propose to make all fractions literals. My implementation simply prints decimal fractions with the exponent notation, e.g. 3/4 is printed as 75-e2, but 2/3 is still printed as (2/3).


Levente


 
      Levente
            --
            eek! Eliot

--
best,Eliot







--
best,
Eliot
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Float parsed as a Fraction bug

J. Vuletich (mail lists)

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.

Also check these comments from Dan: http://lists.squeakfoundation.org/pipermail/squeak-dev/2000-March/013368.html

I don't think this is a bug at all.
BTW, Cuis also supports 1r111111111111 = 12 after this :)

Cheers,
Juan Vuletich

Quoting Eliot Miranda <[hidden email]>:




On Thu, Aug 7, 2014 at 9:05 AM, Levente Uzonyi <[hidden email]> wrote:
On Wed, 6 Aug 2014, Eliot Miranda wrote:

Hi Levente,

On Wed, Aug 6, 2014 at 11:43 AM, Levente Uzonyi <[hidden email]> wrote:
      On Wed, 6 Aug 2014, Eliot Miranda wrote:

            Hi All,
                Squeak trunk also suffers from the Float parsed as a Fraction bug:

            1e-8 class Fraction
            1.0e8 class Float


I'm not entirely sure about it being a bug. I've checked Squeak 3.8 (pre-SqNumberParser), and it also parsed that literal as a Fraction. If I want a Float, I can be explicit and use 1.0e-8.


IMO it very much *is* a bug.  Smalltalk-80 has never supported Fraction literals.  They're always written as division expressions.  Fraction answers false to isLiteral.  Just because it worked that way
doesn't mean it was right.  I suspect no one noticed.  Allowing Fraction literals feels like a big change to me.

It's more like undefined behavior than a bug IMHO, though the lack of #isLiteral makes me think that the Fractions are not intentional. Interesting how Nicolas's SqNumberParser behaves the same way as the previous number parser in this case.



      I made a modified version of Fraction >> #printOn:base: which outputs the literal format if possible. The change "fixes" the debugger (note that itw was way less broken in Squeak than in Pharo
      anyway).
      The only drawback I found is that some fractions become a bit more "complex" when printed, e.g. 3/4 => 75e-2


OK, but is this the right fix?  What does everybody think?  Keep the language unchanged or add Fraction literals and add another incompatibility with other dialects?

I don't think that anyone ever used this "feature" before, so doing what other dialects do is probably the best way to resolve this.
 
Agreed.  Smalltalk-80 v2 had no literal fractions.  ObjectWorks and VisualWorks have never had literal fractions.  I can't speak for other dialects, but I'm fairly sure none of the Smalltalk/V, Team/V lineage had literal Fractions either.
 

If Fractions are literals
- what is the semantics of 1/0 (easy, it is not a literal, but needs to be stated)?
- what is [1/0.1] on: ZeroDivide do: [:ex| #error] ?  Is it 10.0 or #error, i.e. is 1/0.1 10.0 or 1 / 0 followed by the Integer 1?

I did not propose to make all fractions literals. My implementation simply prints decimal fractions with the exponent notation, e.g. 3/4 is printed as 75-e2, but 2/3 is still printed as (2/3).


Levente


 
      Levente
            --
            eek! Eliot

--
best,Eliot
 



 


 
--
best,
Eliot



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Float parsed as a Fraction bug

Eliot Miranda-2
Hi Juan,


On Thu, Aug 7, 2014 at 9:40 AM, J. Vuletich (mail lists) <[hidden email]> 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. 

Dan doesn't say anything about Fraction literals in this message.
 

I don't think this is a bug at all.


What, that 1e-3 is a Fraction, not a Float?
 

BTW, Cuis also supports 1r111111111111 = 12 after this :)

Cheers,
Juan Vuletich

Quoting Eliot Miranda <[hidden email]>:




On Thu, Aug 7, 2014 at 9:05 AM, Levente Uzonyi <[hidden email]> wrote:
On Wed, 6 Aug 2014, Eliot Miranda wrote:

Hi Levente,

On Wed, Aug 6, 2014 at 11:43 AM, Levente Uzonyi <[hidden email]> wrote:
      On Wed, 6 Aug 2014, Eliot Miranda wrote:

            Hi All,
                Squeak trunk also suffers from the Float parsed as a Fraction bug:

            1e-8 class Fraction
            1.0e8 class Float


I'm not entirely sure about it being a bug. I've checked Squeak 3.8 (pre-SqNumberParser), and it also parsed that literal as a Fraction. If I want a Float, I can be explicit and use 1.0e-8.


IMO it very much *is* a bug.  Smalltalk-80 has never supported Fraction literals.  They're always written as division expressions.  Fraction answers false to isLiteral.  Just because it worked that way
doesn't mean it was right.  I suspect no one noticed.  Allowing Fraction literals feels like a big change to me.

It's more like undefined behavior than a bug IMHO, though the lack of #isLiteral makes me think that the Fractions are not intentional. Interesting how Nicolas's SqNumberParser behaves the same way as the previous number parser in this case.



      I made a modified version of Fraction >> #printOn:base: which outputs the literal format if possible. The change "fixes" the debugger (note that itw was way less broken in Squeak than in Pharo
      anyway).
      The only drawback I found is that some fractions become a bit more "complex" when printed, e.g. 3/4 => 75e-2


OK, but is this the right fix?  What does everybody think?  Keep the language unchanged or add Fraction literals and add another incompatibility with other dialects?

I don't think that anyone ever used this "feature" before, so doing what other dialects do is probably the best way to resolve this.
 
Agreed.  Smalltalk-80 v2 had no literal fractions.  ObjectWorks and VisualWorks have never had literal fractions.  I can't speak for other dialects, but I'm fairly sure none of the Smalltalk/V, Team/V lineage had literal Fractions either.
 

If Fractions are literals
- what is the semantics of 1/0 (easy, it is not a literal, but needs to be stated)?
- what is [1/0.1] on: ZeroDivide do: [:ex| #error] ?  Is it 10.0 or #error, i.e. is 1/0.1 10.0 or 1 / 0 followed by the Integer 1?

I did not propose to make all fractions literals. My implementation simply prints decimal fractions with the exponent notation, e.g. 3/4 is printed as 75-e2, but 2/3 is still printed as (2/3).


Levente


 
      Levente
            --
            eek! Eliot

--
best,Eliot
 



 


 
--
best,
Eliot






--
best,
Eliot
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Float parsed as a Fraction bug

Levente Uzonyi-2
On Thu, 7 Aug 2014, Eliot Miranda wrote:

> Hi Juan,
>
> On Thu, Aug 7, 2014 at 9:40 AM, J. Vuletich (mail lists) <[hidden email]> 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.

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?


Levente
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Float parsed as a Fraction bug

J. Vuletich (mail lists)
In reply to this post by Eliot Miranda-2
  Hi Eliot,

Quoting Eliot Miranda <[hidden email]>:

> Hi Juan,
>
>     On Thu, Aug 7, 2014 at 9:40 AM, J. Vuletich (mail lists)
> <[hidden email]> 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. 
>
The attach shows that in ST-80 a CompiledMethod can contain a Fraction  
literal. Source code form for that is '1e-3'. Debugger works as in  
Squeak or Cuis.


>> 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.

He does talk about scientific notation '1e3' and '1e-3' meaning not  
Float, but SmallInteger and Fraction. The subject of this thread is  
"Float parsed as Fraction bug".     

>> I don't think this is a bug at all.
>
>       
>      What, that 1e-3 is a Fraction, not a Float?
       
Yes. That, and allowing for Fraction literals in methods.


>> BTW, Cuis also supports 1r111111111111 = 12 after this :)

Cheers,
Juan Vuletich


St80FractionLiteral.PNG (31K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Float parsed as a Fraction bug

Eliot Miranda-2



On Thu, Aug 7, 2014 at 12:03 PM, J. Vuletich (mail lists) <[hidden email]> wrote:
 Hi Eliot,


Quoting Eliot Miranda <[hidden email]>:

Hi Juan,

    On Thu, Aug 7, 2014 at 9:40 AM, J. Vuletich (mail lists)
<[hidden email]> 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. 


The attach shows that in ST-80 a CompiledMethod can contain a Fraction literal. Source code form for that is '1e-3'. Debugger works as in Squeak or Cuis.

then if you feel strongly change it back, but you need to fix this:

(1/2) isLiteral false

when you do so.


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.

He does talk about scientific notation '1e3' and '1e-3' meaning not Float, but SmallInteger and Fraction. The subject of this thread is "Float parsed as Fraction bug".     


I don't think this is a bug at all.

      
     What, that 1e-3 is a Fraction, not a Float?
      
Yes. That, and allowing for Fraction literals in methods.



BTW, Cuis also supports 1r111111111111 = 12 after this :)

Cheers,
Juan Vuletich
--
best,
Eliot