JuliaLang/julia — pull request #1328 by JeffreySarnoff (2012-10-02 12:14:47+00:00)
Title: better ispow2, nextpow2 and introduce prevpow2

This should be a clean pull request with changes only for ispow2, nextpow2 and adding prevpow2.
I have removed bitsizeof(x) and replaced it with (sizeof(x) << 3), pending consensus.

[bitsizeof(x) supports implementations where a byte is not an octet, e.g. a 16 bit smallest unit,
and comports well with the existing leading_ones, etc functions that are bitcount based,
whether or not this is worth adding bitsizeof into the base namespace is at question]

These versions are more faithful to the math than the prior versions.
They do not treat 0 as a power of two, and do not accept negative values as appropriate input.