Quick Way to Get Number of Digits in an Integer
I am confused. I dropped out of my discrete class, twice actually before just dropping out of school all together, but is one log call some much slower then a bunch of multiplication or division? What is the O(log10)? I guess I don't know how the log10 call works. If it is doing the multiplication in the background then you might be able to optimize it given some restrictions that it doesn't account for. But it seems to me that looping through something, while not immediately, would be much slower the more digits you have.
If anyone knows how the log10 function works I would love to know. I know how to approximate sin and cos from calculus but I can't remeber learning about log. it may seem strange that I want to know after dropping out of school, but it wasn't the learning that drove me away, it was all the homework.
If anyone knows how the log10 function works I would love to know. I know how to approximate sin and cos from calculus but I can't remeber learning about log. it may seem strange that I want to know after dropping out of school, but it wasn't the learning that drove me away, it was all the homework.
Quote:Original post by StubornAH
I am confused. I dropped out of my discrete class, twice actually before just dropping out of school all together, but is one log call some much slower then a bunch of multiplication or division? What is the O(log10)? I guess I don't know how the log10 call works. If it is doing the multiplication in the background then you might be able to optimize it given some restrictions that it doesn't account for. But it seems to me that looping through something, while not immediately, would be much slower the more digits you have.
If anyone knows how the log10 function works I would love to know. I know how to approximate sin and cos from calculus but I can't remeber learning about log. it may seem strange that I want to know after dropping out of school, but it wasn't the learning that drove me away, it was all the homework.
i've also got no idea how log10 works.
Intlog10 is easy. (just count up numbers, ect.)
Floatlog10 is hard. (i have no idea how to do this, without a lut).
Basically, we need to find a f, so that 10^i * 10^f = n
With a lut of all f from 0-1, (which is the range), we could probably implement this in a binary search, and it would be pretty fast.
You would end up with quite a few mults tho. (or divs, if you don't have a 1/pow10 lut.)
From,
Nice coder
ok, you asked for it.
The......
SUPER DOOPER MEGA HAPPY FLOATING POINT MULTI-BIT PRECISION LOGORITHM BASE 10 FUNCTION!!!!!
[lol]
intlut = {0, 1, 10, 100, 1000, 10000, 100000, 100000, 1000000, 10000000, 100000000}
floatlut = {1/10^0.1, 1/10^0.2, 1/20^0.3, ect.}
You could probably get some nice precision from the lut.
Really spazed out code for a binary search for the integer log of a number. (which is what were doing).
Next, is the really spazed out code for doing a binary search for the floating point log of a number.
Does this seem ok?
From,
Nice coder
The......
SUPER DOOPER MEGA HAPPY FLOATING POINT MULTI-BIT PRECISION LOGORITHM BASE 10 FUNCTION!!!!!
[lol]
intlut = {0, 1, 10, 100, 1000, 10000, 100000, 100000, 1000000, 10000000, 100000000}
floatlut = {1/10^0.1, 1/10^0.2, 1/20^0.3, ect.}
You could probably get some nice precision from the lut.
max = 11;min = 0;while (1){g = (min + max) >> 1;if (g = max) {break;} //Your finished.k = intlut[g];if (k > x) { max = g} else {min = g}}
Really spazed out code for a binary search for the integer log of a number. (which is what were doing).
Next, is the really spazed out code for doing a binary search for the floating point log of a number.
Goal = x / lut[g]; //Find the floating point portion of this. You can use a mult w/ a table if you want.//This is the goal for the floating point target to hit.max = Somevalue;min = 0;h = g;while(1) {g = (min + max) >> 1;if (g = max) {break;}if (fraclut[g] > goal) {max = g;}else {min = g}}return (fraclut[g] * intlut[h]);
Does this seem ok?
From,
Nice coder
IIRC log10 is done by breaking it down like this:
And log2 isn't too hard to do in hardware.
log10(x) = log2(x)/log2(10)
And log2 isn't too hard to do in hardware.
About that aproximate the log(10). Is it posible to do it with taylor series? Havent used it in so long i cant remember if you can do it that way.
I once used it to aproximate sin and cos but it was slower that the regular functions. But i did not try to optimize it so it might perhaps have been faster.
I once used it to aproximate sin and cos but it was slower that the regular functions. But i did not try to optimize it so it might perhaps have been faster.
Lut's seem to be the only approach.
But the question is: How did they come up with the data for the lut's?
From,
Nice coder
But the question is: How did they come up with the data for the lut's?
From,
Nice coder
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement