[A89] Re: arctan 2
[Prev][Next][Index][Thread]
[A89] Re: arctan 2
Sebastian writes:
> You can increase the accuracy, but it will require quite a bit of work,
and
> you'll need to understand how it works. But anyway, the binary search
> method suggested in the same thread might be even better.
I went ahead and wrote the arctan routine I described in that thread; the
result can be found in recent versions of the FAT engine. As of this post,
you can obtain the most recent version of the FAT SDK/Source at
http://www.ticalc.org/archives/files/fileinfo/175/17527.html
I'm not sure if my routine will be satisfactory here, because the original
poster wanted it to be accurate to "3 or 4 significant digits." My routine
was designed to be perfectly accurate, but not very "precise" -- it wasn't
meant to distinguish between too many different divisions.
My routine requires a lookup table of WORDs, with the number of entries
equal to the number of distinct angles it should recognize between 0 and 90
degrees. For FAT, we use 576 divisions for a full 360 degrees, so there are
144 divisions between 0 and 90 degrees, thus a 288 bytes lookup table. But
say we're doing degrees, and we want to be accurate to one decimal digit
(allowing us to distinguish between, say, 80.5 and 80.6 degrees) -- that's
900 divisions, or an 1800 byte lookup table. If you want two decimal
digits, you have 9000 divisions, or an 18,000 byte lookup table, etc. As I
said, it's always accurate (even rounding properly), but not to precise.
I also suggest that the original poster try a routine based on the Taylor
expansion -- better yet, take Sebastian's routine and up the accuracy (I
worked with that routine for a bit, and I don't think it looked like it
would be that hard to change).
Niklas writes:
> I don't remember if the last version used it, but the standard way to do
> approximations is to use enough taylor iterations. IIRC the problem is
> that to get those accurate over the entire 90 degrees you need quite a lot
> of them. I think I opted for a sine table and used some form of binary
> search to find the angle, but I'm not sure...
Niklas, I think we discussed that routine a few years ago -- I based my
routine on your explanation =) Say you have a lookup table filled with
tangent values (precalculated at compile time or startup). The arctan
routine takes its input (which is by definition the tangent of some angle)
and uses a binary search-like routine to find the closest value to that in
the lookup table. The index of that value in the table will tell you what
angle its arctangent is.
-Scott