[Pharo-dev] Transcript and ScaledDecimal Issue

Sven Van Caekenberghe sven at stfx.eu
Mon Nov 18 11:19:09 EST 2013


You could try using #storeString as in

Transcript show: (1 / 2) asScaledDecimal storeString

Sven

On 18 Nov 2013, at 17:09, phil at highoctane.be wrote:

> I was playing with ScaledDecimal when doing experiments with numbers in Pharo.
> 
> Now, ScaledDecimal says in its comment:
> 
> "Note that a ScaledDecimal does not printOn: exactly, however it will storeOn: exactly because the full precision fraction is kept in memory."
> 
> This happens to be right when inspecting the expressions.
> 
> Now, I tried to do the following:
> 
> x := 2 asScaledDecimal. 
> y := 1 asScaledDecimal.
> 
> z := (y / x).
> 
> z storeOn: Transcript.
> 
> And z storeOn: Transcript fails miserably.
> 
> This is due to storeOn: doing:
> 
> storeOn: aStream 
> 	"ScaledDecimal sometimes have more digits than they print (potentially an infinity).
> 	In this case, do not use printOn: because it would loose some extra digits"
> 	
> 	self shouldBePrintedAsLiteral
> 		ifTrue: [self printOn: aStream]
> 		ifFalse: [aStream
> 			nextPut: $(;
> 		 	store: numerator;
> 			nextPut: $/;
> 			store: denominator;
> 			nextPut: $s;
> 			store: scale;
> 			nextPut: $)]
> 
> And store: doesn't exists in the ThreadSafeTranscript which happens to be no stream at all.
> 
> Try this out: 
> 
> x := 2 asScaledDecimal. 
> y := 1 asScaledDecimal.
> 
> z := (y / x).
> 
> "works"
> 5.0 storeOn: Transcript.
> Transcript flush.
> 
> "works"
> (1/2) storeOn: Transcript.
> Transcript flush.
> 
> "fails"
> z storeOn: Transcript.
> Transcript flush.
> 
> "works"
> s := (String new: 30).
> st := s writeStream.
> z storeOn: st.
> Transcript 
> 	show: 'storeOn: ', st contents;
> 	cr;
> 	show: z.
> 
> Kind of annoying to do while explaining to kids.
> 
> The ThreadSafe transcript looks like to be subclassed from Object and being no real stream at all.
> 
> Why is it so? 
> 
> Phil
> 
> 
> 





More information about the Pharo-dev mailing list