# NavList:

## A Community Devoted to the Preservation and Practice of Celestial Navigation and Other Methods of Traditional Wayfinding

**Arc cosine**

**From:**Paul Hirose

**Date:**2017 Nov 21, 22:44 -0800

On 2017-11-18 17:53, Robert VanderPol II wrote: > > For computer implementation Cosine is more accurate and takes about 2/3 the time to calc but requires that what ever language you are using be able to handle the acos function well which is not always the case. [LINK: https://gis.stackexchange.com/questions/4906/why-is-law-of-cosines-more-preferable-than-haversine-when-calculating-distance-b] That page mentions a small angle cosine approximation which also came up in a recent thread in the Yahoo Sliderule group: cos x = 1 - x^2 / 2, if angle x is measured in radians. In degrees, the formula becomes cos x = 1 - (x / 180 * π)^2 / 2. For example, if x is 1°, the formula gives .999 847 691. All digits except the last are correct. As the angle approaches zero, the accuracy of the approximation improves. If the angle is small enough, a slide rule can surpass the accuracy of a calculator (if the person with the calculator doesn't know the trick). The formula can be re-arranged as an arc cosine. But to be effective, it requires the small number 1 - cos x, not cos x itself. So it isn't useful with the spherical trig cosine formula. You may as well call the acos() function. Another application for acos() is the computation of π, if it's not a built-in constant in your programming environment. In that case, you can write: pi = acos(-1.0). Some believe that's poor practice due to the rapid change in angle as cosine approaches -1. Instead, they recommend pi = 4.0 * atan(1.0). I tested both formulas on my Windows desktop system (AMD processor). Normally I program in C#, but the language can't access the 80-bit floating point format that's available in the hardware, so I used Silverfrost Fortran 95. A test program calls the 80-, 64-, and 32-bit versions of acos() and atan(), puts the returned value in an 80-bit variable, multiplies by 4 if atan() was called, and prints the result. The top line is the actual value of π to 21 decimal places. 3.141 592 653 589 793 238 462 π 3.141 592 653 589 793 238 60 acos 80 bits 3.141 592 653 589 793 238 60 atan 80 bits 3.141 592 653 589 793 116 00 acos 64 bits 3.141 592 653 589 793 116 00 atan 64 bits 3.141 592 741 012 573 242 30 acos 32 bits 3.141 592 741 012 573 242 30 atan 32 bits On my machine, acos(-1) and 4 * atan(1) compute identical and accurate values of pi. I'd be interested to hear of any system where that's not true.