[squeak-dev] The Trunk: Kernel-nice.842.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Mar 16 22:22:45 UTC 2014


Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.842.mcz

==================== Summary ====================

Name: Kernel-nice.842
Author: nice
Time: 16 March 2014, 11:21:19.525 pm
UUID: c5833439-ae84-4711-a40a-b2db5d766cb3
Ancestors: Kernel-nice.841

Avoid using #reciprocalFloorLog:
#reciprocalFloorLog: does the same as #floorLog: just with more noise.
Once upon a time it was required, but it is not anymore and should be deprecated.

Note that floorLog: already cumulates 3 rounding errors via (self ln / base ln)

(-1 to: (Float fminDenormalized floorLog: 10) + 1 by: -1)
	count: [:i |
		| pow |
		pow := 10 raisedTo: i.
		(pow asFloat floorLog: 10) < i and: [pow asFloat >= pow]].
89

But reciprocalFloorLog: is even worse:

(-1 to: (Float fminDenormalized floorLog: 10) + 1 by: -1)
	count: [:i |
		| pow |
		pow := 10 raisedTo: i.
		(pow asFloat reciprocalFloorLog: 10) < i and: [pow asFloat >= pow]].
 149

=============== Diff against Kernel-nice.841 ===============

Item was changed:
  ----- Method: Float>>absPrintOn:base:digitCount: (in category 'printing') -----
  absPrintOn: aStream base: base digitCount: digitCount 
  	"Print me in the given base, using digitCount significant figures."
  
  	| fuzz x exp q fBase scale logScale xi |
  	self isInfinite ifTrue: [^ aStream nextPutAll: 'Inf'].
  	fBase := base asFloat.
  	"x is myself normalized to [1.0, fBase), exp is my exponent"
+ 	exp := self floorLog: fBase.
- 	exp := 
- 		self < 1.0
- 			ifTrue: [self reciprocalFloorLog: fBase]
- 			ifFalse: [self floorLog: fBase].
  	scale := 1.0.
  	logScale := 0.
  	[(x := fBase raisedTo: (exp + logScale)) = 0]
  		whileTrue:
  			[scale := scale * fBase.
  			logScale := logScale + 1].
  	x := self * scale / x.
  	fuzz := fBase raisedTo: 1 - digitCount.
  	"round the last digit to be printed"
  	x := 0.5 * fuzz + x.
  	x >= fBase
  		ifTrue: 
  			["check if rounding has unnormalized x"
  			x := x / fBase.
  			exp := exp + 1].
  	(exp < 6 and: [exp > -4])
  		ifTrue: 
  			["decimal notation"
  			q := 0.
  			exp < 0 ifTrue: [1 to: 1 - exp do: [:i | aStream nextPut: ('0.0000'
  at: i)]]]
  		ifFalse: 
  			["scientific notation"
  			q := exp.
  			exp := 0].
  	[x >= fuzz]
  		whileTrue: 
  			["use fuzz to track significance"
  			xi := x asInteger.
  			aStream nextPut: (Character digitValue: xi).
  			x := x - xi asFloat * fBase.
  			fuzz := fuzz * fBase.
  			exp := exp - 1.
  			exp = -1 ifTrue: [aStream nextPut: $.]].
  	[exp >= -1]
  		whileTrue: 
  			[aStream nextPut: $0.
  			exp := exp - 1.
  			exp = -1 ifTrue: [aStream nextPut: $.]].
  	q ~= 0
  		ifTrue: 
  			[aStream nextPut: $e.
  			q printOn: aStream]!



More information about the Squeak-dev mailing list