oscbyspro / Ultimathnum

Binary arithmetic reimagined in Swift
Apache License 2.0
9 stars 1 forks source link

Add: T/isPowerOf2 #109

Open oscbyspro opened 1 month ago

oscbyspro commented 1 month ago

The following models can and/or should implement isPowerOf2.

I want at least Count/isPowerOf2 for documentation purposes.

oscbyspro commented 1 month ago

Also, this expression is faster than bit-counting (for small systems integers):

(x > 0) && (x & (x &- 1) == 0)