[squeak-dev] The Inbox: Kernel-nice.721.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Dec 11 22:29:55 UTC 2012


A new version of Kernel was added to project The Inbox:
http://source.squeak.org/inbox/Kernel-nice.721.mcz

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

Name: Kernel-nice.721
Author: nice
Time: 11 December 2012, 11:28:41.487 pm
UUID: d2b8388c-c225-4fee-aaf6-12e059970915
Ancestors: Kernel-nice.720

Provide an exact version for #floorLog: for Number using exact arithmetic.
Current version is not exact, otherwise this count would be zero:
    (-300 to: -1) count: [:n | n ~= ((10 raisedTo: n) floorLog: 10)].

Note however that this won't make #log: exact, and could lead to disagreement between the two functions.

=============== Diff against Kernel-nice.720 ===============

Item was added:
+ ----- Method: Fraction>>floorLog: (in category 'mathematical functions') -----
+ floorLog: radix
+ 	"Unlike super, this version is exact when radix is integer"
+ 	
+ 	| d n |
+ 	radix isInteger ifFalse: [^super floorLog: 10].
+ 	n := numerator floorLog: radix.
+ 	d := denominator floorLog: radix.
+ 	^(numerator * (radix raisedTo: d))
+ 		< (denominator * (radix raisedTo: n))
+ 		ifTrue: [n - d - 1]
+ 		ifFalse: [n - d]!

Item was added:
+ ----- Method: Integer>>floorLog: (in category 'mathematical functions') -----
+ floorLog: radix
+ 	"Unlike super, this version is exact when radix is integer"
+ 	
+ 	radix isInteger ifFalse: [^super floorLog: 10].
+ 	self <= 0 ifTrue: [^DomainError signal: 'floorLog: is only defined for x > 0.0'].
+ 	^(self numberOfDigitsInBase: radix) - 1!

Item was added:
+ ----- Method: ScaledDecimal>>floorLog: (in category 'mathematical functions') -----
+ floorLog: radix
+ 	"Unlike super, this version is exact when radix is integer"
+ 	
+ 	^self asFraction floorLog: radix!



More information about the Squeak-dev mailing list