Re: LOG(x) BASIC function

1999-03-24 Thread Cas Cremers

>>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 checked "the MSX red book". Usually, this explains all these matters. So
we check the index for log... page 93... okay here goes:

Address...2A72H
This routine is used by the factor evaluator to apply the "LOG" function to
a double precision operand contained in the DAC. The function is computed by
polynomial approximation using the list of coefficients at 2DA5H.

I checked this. 2DA5H contains two sequences of double-precision
coefficients, each sequence preceded by a byte that indicates the number of
coefficients in the sequence. The first sequence has four coefficients, the
second five. So that makes a data area of (1+8*4)+(1+8*5)=74 bytes.

Some routines at 2C88H and 2C9AH are used to compute odd or even series of a
polynomal, for the approximation. For input the sequences at 2DA5H are used.

>There must be using a way that requires only a little memory. There are
>many math functions present in the math pack in the ROM, for example LOG,
>EXP, SIN, COS, TAN, ATN. They can't all use large tables, there is simply
>not enough space in a 32K ROM.


So there are. Isn't the MSX red book online somewhere? Am I the only one who
has this book?? I can hardly believe that!

>They might use Taylor sequences or a technique like that. Although it's not
>fast (on a Z80), it results in compact code that needs no tables.


As stated, it uses a minimal table for some coefficients.

It is probably a good thing to use something like the routine used by basic.
Sometimes it's even smart to use the routines embedded in the BIOS - the
math routines for double precision are actually quite good.

>>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.
>
>I don't understand that calculation.


me neither.
>
>By the way, there is not just a 10log, you could use 2log or ln (e-log)
>instead.

yeah but it's wise to just do the e-log (as basic does) and compute the rest
from there.

It all depends on priorities...speed or memory?

>If you don't mind wasting memory, why not make a 256x256 table that
>contains the result of x*y? It would take 128K, but it's fast. Although
>slot switching would degrade the performance a bit.

:) I'm wondering what kind of program we are thinking about here...

>Anyway, I don't think using logs will get your multiplications any faster.
>Maybe it's a better strategy to cut down the number of multiplications you
>need to perform?

Yep. And a normal multiplication isn't even that slow. It's a small loop
that gets traversed 8 times at most...

>I think that the fastest way of multiplying a large amount of numbers on
>MSX would be to use a GFX9000. Think about that... ;)

Sure, and use moonsound ram to store the level graphics 8)

Bye,
Cas

http://www.stack.nl/~cas/par/




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/)




RE: LOG(x) BASIC function

1999-03-19 Thread Hans Otten

Last time i looked into the Microsoft Basic interpreter i remember seeing
appromation of functions like log(x) with things like Taylor sequences. And
quite a reasonable approach for the accuracy needed. 
I still have the commented source of the Basic rom of the Commodore PET,
6502 cpu code (so you know i am old, that was several years before the MSX
was born), and Bill himself added code to that basic interpreter..
All Microsoft interpreters for 8 bit cpu's were constructed in the same way,
very compact code with a small footprint, whether the cpu was 8080, Z80 or
6502. 
Boy, did Microsoft change...

Hans

-Original Message-
From: Maarten ter Huurne [mailto:[EMAIL PROTECTED]]
Sent: vrijdag, maart 19, 1999 01:00 uur
To: [EMAIL PROTECTED]
Subject: Re: LOG(x) BASIC function


At 05:22 PM 3/18/99 +0100, you wrote:

>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?

There must be using a way that requires only a little memory. There are
many math functions present in the math pack in the ROM, for example LOG,
EXP, SIN, COS, TAN, ATN. They can't all use large tables, there is simply
not enough space in a 32K ROM.

They might use Taylor sequences or a technique like that. Although it's not
fast (on a Z80), it results in compact code that needs no tables.

>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)

You'll need an EXP function as well, to get from "log(x*y)" to "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.

I don't understand that calculation.

By the way, there is not just a 10log, you could use 2log or ln (e-log)
instead.

>Although I don't mind wasting that much memory, there has to be a smarter
>way...

If you don't mind wasting memory, why not make a 256x256 table that
contains the result of x*y? It would take 128K, but it's fast. Although
slot switching would degrade the performance a bit.

Anyway, I don't think using logs will get your multiplications any faster.
Maybe it's a better strategy to cut down the number of multiplications you
need to perform?

I think that the fastest way of multiplying a large amount of numbers on
MSX would be to use a GFX9000. Think about that... ;)

Bye,
Maarten



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/)



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/)




Re: LOG(x) BASIC function

1999-03-19 Thread Maarten ter Huurne

At 05:22 PM 3/18/99 +0100, you wrote:

>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?

There must be using a way that requires only a little memory. There are
many math functions present in the math pack in the ROM, for example LOG,
EXP, SIN, COS, TAN, ATN. They can't all use large tables, there is simply
not enough space in a 32K ROM.

They might use Taylor sequences or a technique like that. Although it's not
fast (on a Z80), it results in compact code that needs no tables.

>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)

You'll need an EXP function as well, to get from "log(x*y)" to "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.

I don't understand that calculation.

By the way, there is not just a 10log, you could use 2log or ln (e-log)
instead.

>Although I don't mind wasting that much memory, there has to be a smarter
>way...

If you don't mind wasting memory, why not make a 256x256 table that
contains the result of x*y? It would take 128K, but it's fast. Although
slot switching would degrade the performance a bit.

Anyway, I don't think using logs will get your multiplications any faster.
Maybe it's a better strategy to cut down the number of multiplications you
need to perform?

I think that the fastest way of multiplying a large amount of numbers on
MSX would be to use a GFX9000. Think about that... ;)

Bye,
Maarten



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/)




Re: LOG(x) BASIC function

1999-03-18 Thread shevek

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/)