On Thu, 18 Mar 1999, Patriek Lesparre wrote:

> Hi all,
> 
> I was wondering how BASIC calculates LOG(x). Does it use a look-up table
> (would require massive amounts of memory), some sort of algorithm (would
> require massive amounts of CPU time), or some mixed method?
> 
> I'm trying to speed up multiplication and division (in machinecode) by
> using the following:
> log(x) + log(y) = log(x*y)
> log(x) - log(y) = log(x/y)
> 
> I calculated I'd need about 96kB for a look-up table with reasonable
> accuracy. Because log(256*256)=4.8164 I'd need 48164 x 2 bytes.
> 
> Although I don't mind wasting that much memory, there has to be a smarter
> way...

There is, though it's slower, of course. I believe the usual way
calculators do it is with an aproximation curve. If you ask for the log,
it gives you the result of a function (usually a polynome) which looks
very much like a log. You could use the taylor-series, which can be
calculated quite quick, but is not a very good approximation. I don't know
the taylor-series by heart, but I could look it up. In case you want to
start programming, it will be of the form:
y=a+bx+cx^2+dx^3+....
If i'm working on it anyway, I could find a more optimal way of choosing
the parameters. If you tell me on what range you want to use it, I could
optimize it for you. A faster way is to have a small lookup table and
expect the parts in between to be lineair. It shouldn't be very slow to
calculate that. Than you can make your own desicion how much memory you
want to spend on it (96kB is really too much, I think...)

I hope this helped,

Bye,
shevek


****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****

Reply via email to