|
|
|
|
|
by effigies
5716 days ago
|
|
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. |
|