alphanimal wrote:Does anyone have a SM code snippet to calulate an accurate atan?
I tried it with the infinite series function but that is only valid for values bewteen -1 and 1.
I don't care about performance I just need a reasonably accurate arctan function...
I've been trying to wrap my head around what you're doing and whether and why arctangent is needed.
But for now I'll take it as given.
Where do you need the most accuracy. The difference between 100 and infinity is about 0.01 so is there a point in the upper range that you're OK with pi/2 being the approximate output?
I think some for a calc table stored as an array might work if Taylor series doesn't work for you... but then how to index so that the accuracy is where you need it most. And then there's the issue of whether interpolation is needed.
Here's a simple version with linear indexing and no interpolation:
simple atan table.osm
But it's very inaccurate near zero which may be where you need the most accuracy.
If the indexing was non-linear you could get greater accuracy in the lower range but still support larger values. But you'd still need to decide at what level is pi/2 close enough.