Use fast trig in C on the X16

Tutorials and help articles.

(Posts require approval. See pinned post.)
Forum rules
Post guides, tutorials, and other instructional content here.

This topic area requires approval, so please be patient while we review content to make sure it fits the expectations for this topic area.

Tech support questions should be asked in Hardware or Software support.
SlithyMatt
Posts: 913
Joined: Tue Apr 28, 2020 2:45 am

Use fast trig in C on the X16

Post by SlithyMatt »



1 hour ago, Michael Parson said:




  It seems to be due to how the 6502 does floating point vs the 'traditional' C implementation using IEEE 754.  



In short, the 6502 doesn't do floating point at all. You need to implement it with 8-bit integer math. That's what BASIC does. You could absolutely implement IEEE 754 as a cc65 library, it's just going to be very slow same as any FP implementation.

 

 

paulscottrobson
Posts: 305
Joined: Tue Sep 22, 2020 6:43 pm

Use fast trig in C on the X16

Post by paulscottrobson »



On 3/26/2021 at 5:22 PM, x16tial said:




How do BASICs trig functions work?  Tables of information might already be in ROM.



Basic Trigs, Logs, Exponents and most of those similar functions, and powers, are Taylor Series (not sure about Square Root) which approximate to those values. The BASIC has very little other than a table of the appropriate constants.

You'd be far better off using fixed point arithmetic (say x 256) and a table. You only need degrees 0-45, everything else you can derive easily enough.

 

Edmond D
Posts: 489
Joined: Thu Aug 19, 2021 1:42 am

Use fast trig in C on the X16

Post by Edmond D »



On 3/26/2021 at 10:32 AM, rje said:






SIN calls POLY1, which calls MLTPLY ($BA59), and consequently the multiply bug affects its results.


The multiply bug looks to be addressed according to the sample program listed at https://www.c64-wiki.com/wiki/Multiply_bug

Post Reply