> For the complete documentation index, see [llms.txt](https://wiki.theconfused.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.theconfused.me/reading/astronomical-algorithms.md).

# Astronomical Algorithms

\[WIP]

> People who write their own computer programs often wonder why the machine gives inaccurate planet positions, an unreal eclipse track, or a faulty Moon phase. Sometimes they insist, bewildered, "and I used double precision, too." Even commercial software is sometimes afflicted with gremlins, which comes as quite a shock to anyone caught up in the mystique and presumed infallibility of computers. Good techniques can help us avoid erroneous results from a flawed program or a simplistic procedure--and that's what this book is all about.&#x20;

## 1. Hints and Tips

RA $$\alpha$$(Right Ascension) to degrees conversion: 1h = 15 degrees

\---

Avoid powers in calculations using [Horner's method](https://www.wikiwand.com/en/Horner%27s_method). Suppose that one wants to calculate the value of the polynomial&#x20;

$$y = A + Bx + Cx^2 + Dx^3 + Ex^4$$

It is better to write it as

$$y = A + x(B + x(C + x(D + E)))$$

so that all power functions have disappeared and we only perform additions and multiplications. This is especially well suited for automatic calculation because powers are avoided.&#x20;

\---

Interesting way to exchange two variables X and Y (equivalent to `X, Y = Y, X` in Python):

```
X = X + Y
Y = X - Y
X = X - Y
```

## 3. Interpolation
