Yes, that's a good description of what it does.
Quoting the documentation for my up-coming Math::BigApprox (improved name and now with support for negative numbers and zero):
Math::BigApprox stores numbers as the logarithm of their (absolute) value
(along with separately tracking their sign) and so can keep track of numbers
having absolute value less than about 1e10000000000 with several digits
of accuracy (and quite a bit of accuracy for not quite so ridiculously large
numbers).
Therefore, Math::BigApprox numbers never require a large amount of memory
and calculations with them are rather fast (about as fast as you'll get with
overloaded operations in Perl).
It can even do calculations with numbers as large as 10**(1e300)
(which is too large for this space even when written as "1e..."). But for
such obscenely huge numbers it only knows their magnitude, having zero digits
of precision in the mantissa (or "significand") but having reasonable
precision in the base-10 exponent (the number after the "e"). It would
actually display such a number as something like "1e1.0217e300" since the
usual XeN scientific notation is too cumbersome for such obscenely large numbers.
The simplest calculation is multiplication because we store $x= log($X) and $y= log($Y) so we want to store $z= log( $X * $Y ) and log($X*$Y) == log($X)+log($Y) so we just store $z= $x + $y (to multiply). As Noah said, even adders can multiply on a log table.
The most interesting calculation is addition.
Store $x= log($X)
Store $y= log($Y)
Want $z= log( $X + $Y )
But we don't know $X and $Y, just $x and $y so
Want $z= log( exp($x) + exp($y) )
But exp($x) and/or exp($y) are likely too big to compute so we do the following derivation to get a safer formula:
$z= log( exp($x) + exp($y) )
= log( exp($x)*( 1 + exp($y)/exp($x) ) )
= log( exp($x) * ( 1 + exp($y-$x) ) )
= log(exp($x)) + log( 1 + exp($y-$x) )
= $x + log( 1 + exp($y-$x) )
Now, the only problem is ensuring that exp($y-$x) is not a problem to compute. But if we ensure that $x <= $y (by swapping $x and $y if necessary), then the worst case is something like exp(-1e300), which just gets approximated as 0. And that case means that $y is obscenely larger than $x so $y+$x just gives us back $y, as it should, since we don't have infinite precision.
|