Re: R: LOG(x) BASIC function
On Fri, 19 Mar 1999, Stefano Fronteddu wrote: Taylors rule says that log (1+x) = x - x^2/2 + x^3/3 + + (x^(2n+1)) / (2n+1)! so log x = (x-1) - (x-1)^2/2 + ... +(-1)^n-1 * ((x-1)^n) / n This is correct, but remember that this is an approximation near x=0 (in the original form), so if you want to know log(100), it will have a large error. For more correct values over the whole interval (you need to specify one, preferribly not being infinitely long), there are other ways that take longer for each step, but come much closer to the desired function if x is large. 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/)
R: R: LOG(x) BASIC function
Right, good observation ;-) Thanks, Stefano -Messaggio originale- Da: shevek [EMAIL PROTECTED] A: [EMAIL PROTECTED] [EMAIL PROTECTED] Data: lunedì 22 marzo 1999 14.32 Oggetto: Re: R: LOG(x) BASIC function On Fri, 19 Mar 1999, Stefano Fronteddu wrote: Taylors rule says that log (1+x) = x - x^2/2 + x^3/3 + + (x^(2n+1)) / (2n+1)! so log x = (x-1) - (x-1)^2/2 + ... +(-1)^n-1 * ((x-1)^n) / n This is correct, but remember that this is an approximation near x=0 (in the original form), so if you want to know log(100), it will have a large error. For more correct values over the whole interval (you need to specify one, preferribly not being infinitely long), there are other ways that take longer for each step, but come much closer to the desired function if x is large. 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/) 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/)
R: LOG(x) BASIC function
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+ Taylors rule says that log (1+x) = x - x^2/2 + x^3/3 + + (x^(2n+1)) / (2n+1)! so log x = (x-1) - (x-1)^2/2 + ... +(-1)^n-1 * ((x-1)^n) / n I hope to be helpful to you, bye Stefano --- Fronteddu Stefano Student in Software Engineering [EMAIL PROTECTED] [EMAIL PROTECTED] http://members.xoom.it/dudduMSX, Sardinia, Robotics, Friends http://computer.digiland.it/1461 MSX Soft Tips Page Member of Miri Software - Italy http://Frengo.dragonfire.net/MSX.HTM ICQ: 21401454 0338/3645458 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
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
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/)
LOG(x) BASIC function
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... Greetz, Patriek 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
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/)