[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: RE: log to the base 2
In a discussion about obtaining log base 2, Rodrigo Alfaro
<firstname.lastname@example.org> wondered how Stata calculates logs.
> What do you mean with easy?
> I think that the famous book of Abramovitch "Handbook of Formula...." (maybe
> the reference there... I have it in some backup file) explains that the
> algorithm for the approximation of logarithm works better for base 10 than
> other lower base (e, 2 or whatever). For that reason, log10 is computed and
> log or ln is obtained as a second result using the property of logarithms.
> Therefore the natural was added and the unnatural or common is the original.
> I don't know how Stata works here (interesting question), but if you take a
> regular scientific calculator you will see log10 and ln not log2 or log5...
> the chip was produced in 60 (maybe before) with the 'tables' for log10.
Modern computers in fact obtain logs from log base 2, using
log_y(x) = log_2(x)/log_2(y)
They use log base 2 as the mother function because of how floating-point
numbers are stored. Floating point number z is stored as (s, e), where
z = s * 2^e, -2 < s < 2
Understand, you may write 200, but your computer stores that as
1.5625*2^7, and it is 1.5625 and 7 that your computer stores.
(Of course, what the computer actually stores is in binary, and
the numbers are 1.1001 and 111 in base 2.)
In any case,
log_2(z) = log_2(s * 2^e)
= log_2(s) + log_2(2^e)
= log_2(s) + e
Thus, one need only obtain log_2(s) where 0<s<2, and that is not a difficult
* For searches and help try: