[WP-34S] DEG and RAD - diffs
06-06-2014, 01:31 AM
Post: #14
 Claudio L. Senior Member Posts: 1,883 Joined: Dec 2013
RE: [WP-34S] DEG and RAD - diffs
(06-05-2014 10:32 PM)Paul Dale Wrote:
(06-05-2014 09:38 PM)Claudio L. Wrote:  Smaller angles are harder test cases and have more errors on trig function algorithms.

Why?

This must depend greatly on the algorithm used.

For example, using a Maclaurin series for the trigonometric functions gives very good results for all of the trig functions for small inputs.

- Pauli

Indeed: For very small angles, a couple terms of Taylor gives you great results. The smaller the value the less terms you need.
However, CORDIC accumulate angles from large to small, adding smaller and smaller numbers to bring a target to zero. This is really bad for precision, because it forces you to start adding large terms first that cancel each other. I was able to get good results by starting the loop at a more advanced stage, where angles are in the same order of magnitude as the argument to avoid the large errors. This way I was able to obtain good accuracy on all digits even for small angles, but the price was to triple the storage space since I need calibrated constants to start the loop arbitrarily at any location.
If the implementation doesn't do this, it loses a lot of digits.
There's other cases where this can't be avoided: cosh() for example. The small angles case has a result that's very close to one (you never have this with the normal COS() since you have to calculate sin(PI/2-alpha)). I found a way around it by storing the (COSH-1) instead of COSH (which gives me back the digits when the result is close to one), and also needed extra iterations. Unless you take all those precautions, CORDIC is very prone to error on small angles, and I suspect many implementations in the early days were very crude.

Claudio
 « Next Oldest | Next Newest »