[squeak-dev] The Inbox: Kernel-ul.1410.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Fri Sep 10 11:58:18 UTC 2021


Le ven. 10 sept. 2021 à 02:25, <commits at source.squeak.org> a écrit :

> Levente Uzonyi uploaded a new version of Kernel to project The Inbox:
> http://source.squeak.org/inbox/Kernel-ul.1410.mcz
>
> ==================== Summary ====================
>
> Name: Kernel-ul.1410
> Author: ul
> Time: 10 September 2021, 2:24:41.798614 am
> UUID: 471ec32e-c74e-4a21-b5df-431f058878fe
> Ancestors: Kernel-ul.1409
>
> - let all Numbers respond to #isPowerOfTwo.
> - removed Integer >> #isPowerOfTwo because it was not used: all subclasses
> implement that method
> - speed up Float >> #isPowerOfTwo at the cost of relying on the exact bit
> representation
>
> =============== Diff against Kernel-ul.1409 ===============
>
> Item was changed:
>   ----- Method: Float>>isPowerOfTwo (in category 'testing') -----
>   isPowerOfTwo
> +       "Return true if the receiver is an integral power of two.
> Optimized version."
> +
> +       | firstWord |
> +       (self basicAt: 2) = 0 ifFalse: [ ^false ].
>
Hi Levente,
above test does not work for denormalized...
when biased exponent is zero, we must check that significand bitCount = 1...

+       ((firstWord := self basicAt: 1) bitAnd: 16rFFFFF) = 0 ifFalse: [
> ^false ].
> +       (firstWord := firstWord bitShift: -20) >= 16r7FF ifTrue: [ ^false.
> "infinitiy, negative, nan" ].
> +       ^firstWord >= 16r3FF!
> -       "Return true if the receiver is an integral power of two."
> -       ^self significand = 1.0!
>
> Item was added:
> + ----- Method: Fraction>>isPowerOfTwo (in category 'testing') -----
> + isPowerOfTwo
> +       "Return true if the receiver is an integral power of two."
> +
> +       ^false!
>
> Item was removed:
> - ----- Method: Integer>>isPowerOfTwo (in category 'testing') -----
> - isPowerOfTwo
> -       "Return true if the receiver is an integral power of two."
> -
> -       ^self strictlyPositive and: [ (self bitAnd: self - 1) = 0 ]!
>
> Item was added:
> + ----- Method: Number>>isPowerOfTwo (in category 'testing') -----
> + isPowerOfTwo
> +       "Return true if the receiver is an integral power of two."
> +
> +       self subclassResponsibility!
>
> Item was added:
> + ----- Method: ScaledDecimal>>isPowerOfTwo (in category 'testing') -----
> + isPowerOfTwo
> +       "Return true if the receiver is an integral power of two."
> +
> +       ^fraction isPowerOfTwo!
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210910/aa64a58f/attachment.html>


More information about the Squeak-dev mailing list