Fractions bug

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

Fractions bug

J Pfersich
I found this:
st> var5 := Fraction numerator: 3 denominator: 4 !
Fraction new "<0x1057dc0>"
st> var5 printString !
'3/4'
st> var5 storeOn: stdout !
(Fraction numerator: 3 denominator: 3)Fraction new "<0x1057dc0>"
st>
The numerator is also used as the denominator.

I also found that the class comment is inaccurate, the arithmatic operators
do not answer a reduced fraction, the reduce private method is never accessed.



_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Fractions bug

S11001001
On Sun, 2007-01-21 at 22:40 -0700, J Pfersich wrote:
> st> var5 printString !
> '3/4'
> st> var5 storeOn: stdout !
> (Fraction numerator: 3 denominator: 3)Fraction new "<0x1057dc0>"
> st>
> The numerator is also used as the denominator.

heh :)  See attachment.  (Paolo: fixed in
[hidden email]--2007-nocandy/smalltalk--backstage--2.2--patch-4
"fix wrong varref in Fraction>>#storeOn:".)

> I also found that the class comment is inaccurate, the arithmatic operators
> do not answer a reduced fraction, the reduce private method is never accessed.

See the category 'arithmetic' method bodies.

st> ((3/4) * (2/3)) inspect!
An instance of Fraction
  numerator: 1
  denominator: 2

--
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
"Peta" is Greek for fifth; a petabyte is 10 to the fifth power, as
well as fifth in line after kilo, mega, giga, and tera.
  -- Lee Gomes, performing every Wednesday in his tech column
     "Portals" on page B1 of The Wall Street Journal

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

fraction-storeon.diff (606 bytes) Download Attachment
signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Fractions bug

Paolo Bonzini
In reply to this post by J Pfersich

> I also found that the class comment is inaccurate, the arithmatic operators
> do not answer a reduced fraction, the reduce private method is never
> accessed.

Please verify your assertions, as you obviously did (instead) for the
#storeOn: bug which is real.  #reduce is never called because the
arithmetic operators compute gcd's on their own for speed.

st> ^(3/4)+(1/4)
st> !
1

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Fractions bug

J Pfersich
Sorry, I didn't include the example, so here it is:

st> var5 := Fraction numerator: 123 denominator: 3 !
Fraction new "<0x1041b08>"
st> var5 printNl !
123/3
Fraction new "<0x1041b08>"
st> (var5 * (Fraction numerator: 1 denominator: 1)) printNl !
123/3
Fraction new "<0x104d998>"
st> (var5 * (Fraction numerator: 2 denominator: 1)) printNl !
246/3


At 09:40 AM 1/22/2007 +0100, Paolo Bonzini wrote:

>>I also found that the class comment is inaccurate, the arithmatic operators
>>do not answer a reduced fraction, the reduce private method is never
>>accessed.
>
>Please verify your assertions, as you obviously did (instead) for the
>#storeOn: bug which is real.  #reduce is never called because the
>arithmetic operators compute gcd's on their own for speed.
>
>st> ^(3/4)+(1/4)
>st> !
>1
>
>Paolo



_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Fractions bug

Paolo Bonzini
J Pfersich wrote:
> Sorry, I didn't include the example, so here it is:
>
> st> var5 := Fraction numerator: 123 denominator: 3 !

Fair enough.  If you start from unreduced fractions, you get unreduced
results.

Thanks,

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk