News for hackers. Stuff that matters.
Re:Write A Function To Determine If A Number Is A Power Of 2 by effigies on Monday October 18, 2010 @12:18PM (#1804045)
With floating point, the first 9 bits are sign and exponent. You could thus check with:

    int ispoweroftwo(float x) {
        return !(*(int*)(&x) << 9);
    }
This only works for exact powers of two, though. It's possible to get something that's really close that will fail this.

There are no comments on this comment yet.