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

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Tue Dec 11 22:50:24 UTC 2012


Note: I don't know if it's a good idea to make floorLog: and log:
opinion differ, so the place of such change is the inbox...
However I already did that to aFloat floorLog: 2 which might disagree
with (aFloat log: 2) floor...

An example of failure is (8.0 predecessor floorLog: 2) = (8.0
predecessor log: 2) floor
But you can discover many other with this snippet

| f bad |
bad := OrderedCollection new.
(1 + (Float fminDenormalized floorLog: 2)  to: (Float fmax floorLog: 2))
	do: [:n |
		f := (1.0 timesTwoPower: n) predecessor.
		(f floorLog: 2) = (f log: 2) floor ifFalse: [bad add: f].
		f := 1.0 timesTwoPower: n.
		(f floorLog: 2) = (f log: 2) floor ifFalse: [bad add: f].
		f := (1.0 timesTwoPower: n) successor.
		(f floorLog: 2) = (f log: 2) floor ifFalse: [bad add: f]].
^bad

2012/12/11  <commits at source.squeak.org>:
> 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