Re: intdiv

new topic     » goto parent     » topic index » view thread      » older message » newer message
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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu