Re:Why is division so much more complex than other arithmeti...
by foota on Friday August 11, 2023 @05:14PM
(#37094121)
Could you explain a little more of post a reference?
[ Parent
| on HN ]
Re:Why is division so much more complex than other arithmeti...
by psychphysic on Friday August 11, 2023 @05:22PM
(#37094218)
If
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.
Re:Why is division so much more complex than other arithmeti...
by foota on Friday August 11, 2023 @05:56PM
(#37094538)
Ah, I get it now. All we need is a logarithm oracle and we're good to go :)
Re:Why is division so much more complex than other arithmeti...
by ithkuil on Friday August 11, 2023 @06:54PM
(#37095054)
Indeed, with lookup tables, if you've seen one, you've seen them all
Re:Why is division so much more complex than other arithmeti...
by foota on Friday August 11, 2023 @07:27PM
(#37095269)
Unfortunately, if you've seen them all, you also need to store them all :-)
Re:Why is division so much more complex than other arithmeti...
by xpe on Friday August 11, 2023 @09:15PM
(#37095944)
Actually, everything will work out fine if we just could pick the optimal algorithm for each situation. How? Use an oracle to pick the right algorithm!
Re:Why is division so much more complex than other arithmeti...
by a_e_k on Friday August 11, 2023 @07:35PM
(#37095324)
That's essentially how IEE 754 floating-point works. You can think of it as a piece-wise linear approximation of the base-2 logarithm.
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 );
}