A × B = C
then log A + log B = log C
And if D^E = F
then E × log D = log F
Mostly a tongue in cheek comment but if you don't know log rules at all check out log tables [0]. And you'll see that if you use log values then multiplication and division become addition and subtraction and equally simply.Relies on you either having stored the needed data or efficiently calculating logirithms and antilogirithims.
For non-negative values, the exponent (upper) bits give the integer part of the logarithm and the significand (lower) bits approximate the fractional part (i.e., the mantissa).
In other words, you can do:
float approxLog2( float value )
{
assert( value > 0.0f );
auto bits = std::bit_cast< int32_t >( value );
auto exponent = ( bits >> 23 ) - 127;
auto significand = bits & ( ( 1 << 23 ) - 1 );
return exponent + significand / static_cast< float >( 1 << 23 );
}
This will be exact at powers of two, and within 0.0860748291 of the true value in between (always being slightly too low).