Quote:
I've downloaded a program called 'huey'. It works okay but the trig functions are not that accurate and 'huey' does not remove the sine circles so after 2.pi you get gobbledeegook.
I've also been looking at KIMATH by mos technology. Anybody got any more maths for the 6502?
My article and files and their descriptions for large look-up tables for hyper-fast, accurate 16-Bit scaled-integer math are at
http://wilsonminesco.com/16bitMathTables/index.html. This is in some cases
many hundreds of times as fast as actually calculating the functions, and every last bit will be correct.
Alternately for SIN & COS functions you can take the first four terms of the infinite series and tweak the coefficients slightly (I can give you mine if you're interested) to compensate for the fact that you're only using four, and in 16-bit math, I've never seen them be more than 1 lsb off. It's only accurate like this for a fraction of a circle though-- 45° (π/4 radians) IIRC-- and then you have to handle the other half of the quadrant from the alternate function, and the other quadrants, separately. TAN is best returned as a rational number giving both the SIN and the COS as a fraction, since TAN has this nasty habit of going to ±inf at ±90°. Using the pair you can literally handle the entire range since the COS goes to 0 there.
ARCTAN is a function that interpolates quite nicely from a surprisingly small table. With a 17-point (16-segment) optimized table for 0-45°, I found the maximum error to be under .02°. Using 16-bit scaled-integer math, the resolution is the worst near 0, at about .007°. The accuracy of the output increases much faster than the size of the table. I don't remember exactly, but it was something like that if you double the size of the table, you get four times or eight times the accuracy.
http://www.awce.com/pak1.htm has serial-interfaced floating-point coprocessors which are more convenient but not nearly as fast, and of course floating-point is very inefficient to handle in a processor that doesn't have a FP unit, and it's unnecessary for most applications outside of calculators.
See my links at
http://wilsonminesco.com/links.html, particularly the section called "math (including coprocessors), algorithms, OSs, programming languages, programmers' info" which is about 40% of the way down the page. Our own wiki is mentioned there too, with the math index
http://6502org.wikidot.com/software-math (although so far that one doesn't have any trig).