First off, I don't know how to do subscripts, so I'm sorry
Secondly... What??? I've been trying to wrap my head around this for a bit, but the best I can think of is that they would switch places if they were decimals, so I tried that, but nope. Log base .6 of .2 is some fraction, and same with almost every other decimal base of .2, and I honestly can't understand that at all
Please help
A method for approximating log(5) (base 2) ...
math - How to compute floor(log2(5**x)) without floating point arithmetic or long integer computation - Stack Overflow
Logarithm question: I can't figure out how (log5)^2+(log2)^2+2log2log5 equals 1 | Free Math Help Forum
Reddit - The heart of the internet
What is log base 2?
How do you calculate log base 2?
How do I calculate the logarithm in base 2?
To calculate the logarithm in base 2, you probably need a calculator. However, if you know the result of the natural logarithm or the base 10 logarithm of the same argument, you can follow these easy steps to find the result. For a number x:
-
Find the result of either
log10(x)orln(x). -
Divide the result of the previous step by the corresponding value between:
-
log10(2) = 0.30103; or -
ln(2) = 0.693147.
-
-
The result of the division is
log2(x).
Videos
I was fiddling around with log(5) (the logarithm is of base 2) , trying to find a sharp bound for it using elementary methods .
log(5) = log(5 * 2k / 2k ) = log(10 * 2k-1 ) - k , now for k=11 , we have log(5)=log(10*1024)-11 , but 1024>1000=103 : log(5)>log(104 )-11 = 4(1+log(5))-11 or
log(5) < 7/3
Can this method be generalized ? If we pick a bigger k can we get a better bound by using the same method (finding a power of 10 that is a bit smaller than 2k-1 ) ?
As you correctly note, log2(5**x) == x * log2(5). log2(5) is a constant, which can be approximated to 2.3219281.
However, floats aren't allowed per the question. Not an issue!
log2_5 = 23219281;
scale = 10000000; // note log2_5/scale is the actual value
result = x * log2_5;
output = (result - (result % scale)) / scale;
By reducing result by result % scale, dividing it by scale will be an integer division, not a float.
for a simple, efficient and mathematically elegant way...
floor(x*log2(5))
Since x has integer values 1 to 100, various tests can to made to find the "best" that uses an integer multiply and a divide by power_of_2.
f(x) = x*a integer_divide power_of_2
For
f(x) = floor(x*log2(5)) = floor(x*some_float_c) the value of some_float_c is bounded by 100 minimum and maximums below.
x f(x) mn mx
f(x)/x (f(x) + 1)/x
1 2 2.00000 3.00000
2 4 2.00000 2.50000
3 6 2.00000 2.33333
...
59 136 2.30508 2.32203
...
87 202 2.32184 2.33333
...
98 227 2.31633 2.32653
99 229 2.31313 2.32323
100 232 2.32000 2.33000
The maximum min is 2.32184 and the minimum max is 2.32203, :
2.32184... <= some_float_c < 2.32203...
Since we cannot use float, find some_integer/some_power_of_2
2.32184... <= some_integer/some_power_of_2 < 2.32203...
ceil(some_power_of_2 * 2.32184...) <= some_integer < floor(some_power_of_2 * 2.32203...)
min max
2.32184 2.32203
2 5 4
4 10 9
8 19 18
...
1024 2378 2377
2048 4756 4755
4096 9511 9511 < first one where min <= max
8192 19021 19022
So 9511/4096 is the "simplest" and is a "best" candidate.
f(x) = (x*9511) integer_divide_by_power_of_2 4096
// In C
unsigned y = (x*9511u) >> 12;