Re: intdiv
- Posted by mattlewis (admin) May 13, 2012
- 1493 views
bill said...
public function powof2(object p) return not (and_bits(p, p-1)) end function constant MAXINT = 1073741823\\ constant MININT = -1073741824 ? powof2(MININT) => 0
Simple error: it fails because and_bits works on
integers and MININT - 1 is not an integer.
I'm not following what you're saying. First, which power of 2 is -1073741824?
MININT is 0xC0000000. And MININT-1 = 0xBFFFFFFF. When you bitwise-and those two together, you get 0x80000000, which is not 0, and therefore correctly identifies MININT as not a power of 2.
On the other hand, powof2(-MININT) returns the correct result. Note that -MININT is not an integer.
Matt