<div dir="ltr"><div><div>Ah, but I now see that you excluded negative powers...</div><div>
<div><br></div>    (2 raisedTo: -3) isPowerOfTwo. <br></div><div><br></div>That's a choice...<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 10 sept. 2021 à 13:58, Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 10 sept. 2021 à 02:25, <<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Levente Uzonyi uploaded a new version of Kernel to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/Kernel-ul.1410.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/inbox/Kernel-ul.1410.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Kernel-ul.1410<br>
Author: ul<br>
Time: 10 September 2021, 2:24:41.798614 am<br>
UUID: 471ec32e-c74e-4a21-b5df-431f058878fe<br>
Ancestors: Kernel-ul.1409<br>
<br>
- let all Numbers respond to #isPowerOfTwo.<br>
- removed Integer >> #isPowerOfTwo because it was not used: all subclasses implement that method<br>
- speed up Float >> #isPowerOfTwo at the cost of relying on the exact bit representation<br>
<br>
=============== Diff against Kernel-ul.1409 ===============<br>
<br>
Item was changed:<br>
  ----- Method: Float>>isPowerOfTwo (in category 'testing') -----<br>
  isPowerOfTwo<br>
+       "Return true if the receiver is an integral power of two. Optimized version."<br>
+ <br>
+       | firstWord |<br>
+       (self basicAt: 2) = 0 ifFalse: [ ^false ].<br></blockquote><div>Hi Levente,</div>above test does not work for denormalized...</div><div class="gmail_quote"><div>when biased exponent is zero, we must check that significand bitCount = 1...</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+       ((firstWord := self basicAt: 1) bitAnd: 16rFFFFF) = 0 ifFalse: [ ^false ].<br>
+       (firstWord := firstWord bitShift: -20) >= 16r7FF ifTrue: [ ^false. "infinitiy, negative, nan" ].<br>
+       ^firstWord >= 16r3FF!<br>
-       "Return true if the receiver is an integral power of two."<br>
-       ^self significand = 1.0!<br>
<br>
Item was added:<br>
+ ----- Method: Fraction>>isPowerOfTwo (in category 'testing') -----<br>
+ isPowerOfTwo<br>
+       "Return true if the receiver is an integral power of two."<br>
+ <br>
+       ^false!<br>
<br>
Item was removed:<br>
- ----- Method: Integer>>isPowerOfTwo (in category 'testing') -----<br>
- isPowerOfTwo<br>
-       "Return true if the receiver is an integral power of two."<br>
-       <br>
-       ^self strictlyPositive and: [ (self bitAnd: self - 1) = 0 ]!<br>
<br>
Item was added:<br>
+ ----- Method: Number>>isPowerOfTwo (in category 'testing') -----<br>
+ isPowerOfTwo<br>
+       "Return true if the receiver is an integral power of two."<br>
+ <br>
+       self subclassResponsibility!<br>
<br>
Item was added:<br>
+ ----- Method: ScaledDecimal>>isPowerOfTwo (in category 'testing') -----<br>
+ isPowerOfTwo<br>
+       "Return true if the receiver is an integral power of two."<br>
+ <br>
+       ^fraction isPowerOfTwo!<br>
<br>
<br>
</blockquote></div></div>
</blockquote></div>