Saturday, 3 June 2017

logarithms - Approximation log2(x)



Can anyone share an easy way to approximate log2(x), given x is between 0 and 1?



I'm trying to solve this using an old fashioned calculator (i.e. no logs)



Thanks!




EDIT: I realize that I stepped a bit ahead. The x comes in the form of a fraction, e.g. 3/8, which is indeed between 0 and 1, but could also be written as log2(3) - log2(8). I am hoping there is a quick way to approximate this calculation to let's say 2 decimals


Answer



First normalize the value to the range [1,2), multiplying by 2 as long as necessary (the number of multiplies will form the integer part of the logarithm).



Then use the formula



log2(1+t1t)=2ln(2)(t+t33+t55) evaluating for



t=x1x+1which will be in range [0,13). It will converge reasonably quickly, about one correct decimal per term.







Another option is to keep a tabulated list of constants such as 1.5,1.25,1.125 together with their logarithms, and use



x>Cilog2(x)=log2(xCi)+log(Ci).



At the same time as you divide x by the constants (but keeping x>1), you accumulate the logarithms of these constants. When x1, you have it. You can choose the set of constants that suits you best.


No comments:

Post a Comment

real analysis - How to find limhrightarrow0fracsin(ha)h

How to find lim without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...