Correct me if I'm wrong, but I don't believe the bit twiddling trick would work on floating point representations, would it?
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.