Talk:CORDIC
Validity
The task description currently says that the algorithm is valid for values of alpha up to π/2 but it seems that that limit should be π/4. The accuracy of the algorithm at values slightly smaller than π/4 isn't very good (for example: at 0.784 radians), but it's *much* better than the accuracy of the algorithm at values slightly larger than π/4 (for example 0.786 radians). --Rdm (talk) 13:31, 10 July 2023 (UTC)
- Using the Algol 68 version, I get the following:
angle cordic cos cos difference cordic sin sin difference cordic tan tan difference 0.7810: 0.710185 0.710185 2.3725799e-10 | 0.704015 0.704015 2.3933777e-10 | 0.991311 0.991311 6.6818373e-10 0.7819: 0.709571 0.709571 3.73174525e-9 | 0.704634 0.704634 3.75788911e-9 | 0.993043 0.993043 1.05185740e-8 0.7828: 0.708956 0.708956 1.7983937e-10 | 0.705253 0.705253 1.8078339e-10 | 0.994778 0.994778 5.0734306e-10 0.7837: 0.708340 0.708340 3.44724094e-9 | 0.705872 0.705872 3.45929518e-9 | 0.996515 0.996515 9.73335601e-9 0.7845: 0.707724 0.707724 6.95373681e-9 | 0.706489 0.706489 6.96588398e-9 | 0.998256 0.998256 1.96510264e-8 0.7854: 0.707107 0.707107 1.1102230e-16 | 0.707107 0.707107 0.00000000e+0 | 1.000000 1.000000 1.1102230e-16 0.7863: 0.706489 0.706489 3.27581606e-9 | 0.707724 0.707724 3.27010385e-9 | 1.001747 1.001747 9.27351729e-9 0.7871: 0.705872 0.705872 6.79132328e-9 | 0.708340 0.708340 6.76765832e-9 | 1.003497 1.003497 1.92424936e-8 0.7880: 0.705253 0.705253 3.22337856e-9 | 0.708956 0.708956 3.20654492e-9 | 1.005250 1.005250 9.14117892e-9 0.7889: 0.704634 0.704634 6.74470002e-9 | 0.709571 0.709571 6.69777700e-9 | 1.007006 1.007006 1.91443004e-8 0.7898: 0.704015 0.704015 3.17049509e-9 | 0.710185 0.710185 3.14294724e-9 | 1.008765 1.008765 9.00724273e-9
--Tigerofdarkness (talk) 14:18, 10 July 2023 (UTC)
- Among the scientific articles I have read on the topic, a few mention a [0,π/4] validity but the others stick to [0,π/2]. For me, the above issue comes from accumulation of rounding errors: the algorithm starts by trying to withdraw π/4 from the angle: if it can't, it will then substract arctan(0.1) ≈ 3π/100 a number of times, generating a bigger rounding error. To improve accuracy, it probably makes sense to find the appropriate 'CORDIC window' by calling a trigonometric identity, such as tan(2a) = 2tan(a)/(1-tan²(a)), before starting the calculation. Successors of the HP-35, the first pocket calculator with CORDIC inside, compute mathematical functions with 'extended real numbers' (mantissa with 3 extra digits) to avoid these errors.
--Aerobar (talk) 20:22, 10 July 2023 (UTC)
- I see I should have said a bit more... Doesn't the accuracy depend on how many values you have in the arctan table and the value of epsilon ?
- It seemed OK to me and not particularly less accurate around pi/4. For some reason, I assumed we should try to minimise the number of iterations so I made epsilon 10^-9 in the Algol 68 sample - with smaller epsilons, more accurate values can be obtained.
- --Tigerofdarkness (talk) 21:40, 10 July 2023 (UTC)
- The size of the arctan table is completely defined by the internal floating point precision, but the key for accuracy shall lie in the appropriate selection of epsilon - there even might be different values for it, depending on the number to compute. One can also decide to exit the main loop after a predefined number of iterations, considering that overcomputing destroys precision. The expertise of early computer scientists was in such tweaking!
- --Aerobar (talk) 20:53, 25 July 2023 (UTC)