Re: LF: Floating-Points and Trig...


[Prev][Next][Index][Thread]

Re: LF: Floating-Points and Trig...



On Wed, 9 Jul 1997 09:51:13 -0500 "Aaron A. Hill" <mozart@inlink.com>
writes:

>Greetings,
>
>I am new to this list.  I hope that I can get all of my questions 
>answered...
>[...]

>Floating-Points:  As far as I know (from reading the docs from 
>Motorola), the MC68000 that is in the TI-92 does not natively support 
>floating-point arithmetic.  Does anyone know of a way to simulate 
>floating-point support?  The only solution I came up with was to 
>"scale up" all of my decimals to the point that I could perform the 
>standard integer operations and not "lose" my accuracy.  Would this be 
>a viable alternative?

That's right, no built-in floating point.  The best way for TI-92 stuff
is to scale up the numbers.  If scale up all values by a factor of 256,
you will have more than enough precision for most tasks, and can use
bit shifts for adjusting the values up and down.  Note that when you are
multiplying signed values, you can only use -128 to 127, and with
unsigned values, 0 to 255, because the multiplication only uses 16
bit sources.  

There are more "advanced" ways to simulate floating point that hold a
seperate base and exponent and allow you to accurately represent
very large and very small values.  However this is very slow!

>Trigonometry:  I am a senior in high school (this '97-'98 year).  I 
>have finished Pre-Calculus during my Junior year.  I know about the 
>sequence that simulates a Sin(x) function.  I could probably impliment 
>this function, but I fear that I am going to take a big performance 
>hit.  The sequence requires about four or five iterations to most 
>accurately represent the Sin(x) function.  Here is the sequence (in 
>"ti-math"):
>	PwrSin(x)=x - x^3/(3!) + x^5/(5!) - x^7/(7!) + x^9/(9!) ...
>This function will work (I have tested it on my TI-92 and with BASIC 
>on my computer). 

Don't do this!  On a regular 68000 (as in the TI-92), it will be
very slow.  Since you have to do a lot of multiplication, division
and scaling, this can take much too long. 

In addition, this method is very inaccurate.  If you only do the first
few terms of the function, you will have extremely incorrect results with
the
larger angles.  If you do more terms, round-off error (due to the very
limited precision of fixed-point) will result in serious inaccuracy as
well.  That probably didn't make much difference when using floating
point, but when using fixed point it certainly does!

For example, When you go all the way to x^15/(15!) when scaling numbers
up
by 1000, it tells you that sin(2*PI) is -.092!  If you go to 3*PI, you
get
the even more absurd result of -80!  Going up to x^19/(19!) gets
sin(2*PI) right, but still thinks that sin(3*PI) is -4.772!

>The only solution I could think of is to impliment a 
>pseudo-Sin-Table.  This table would take up some space in the program. 
> Howver, I think that it would be faster; I require a faster function 
>and would not mind to sacrifice a little extra memory.  Has anyone 
>implimented a Sin-Table or does anyone have a fast version of the 
>PwrSin(x) function?

When programming for 68000, I always use tables of trig functions.
In order to save space, a good trade-off is to have a table of only
the sines of angles in the first quadrant.  Extrapolating the sine
and cosine of any angle from this is very fast compared to calculating
the value when you need it.

--
Patrick Davidson (ariwsi@juno.com)
Visit my home page!  Stuff for Amiga, TI-85, TI-92, even DOS!
http://www.calweb.com/~kwdavids/patrick/
http://www.toptown.com/hp/ariwsi/


References: