A few years back I wrote a 16 bit fixed point trig package in Forth for a microcontroller. I used it for inverse kinematics and navigation for several hobby robots. One was a small robot arm
https://youtu.be/14BX50aHDAk.
I just ported it line by line from Forth to 6502 assembly using my page zero stack macros and posted it to my GitHub repo:
https://github.com/Martin-H1/6502/blob/ ... trig16.asmIt subdivides the unit circle into 1024 binary radians which was more than enough accuracy for my uses. The sine and cosine functions being table driven seem robust. But the tangent function has its limits. I scaled the output of tangent to be useful from -80 degrees to 80 degrees, but it quickly goes out of range near the Y axis. Since robots are physical machines I avoided having the robot move in ways that provoked those values.
The asin function uses a binary search to find the corresponding angle for the sine value, and has good performance.
The atan2 function uses CORDIC with eight angle samples, it's quick, but only gets to within a few brads. The one exception is when the point has a negative X component and zero Y component, then it gives the wrong answer. But again with a robot that would be a point inside the robot and not in the work envelope.
Anyway it's MIT licensed if you find it useful. Let me know if you have improvement suggestions, or spot any bugs. Particularly in the CORDIC routine.