The Swiss Ephemeris calculates speed by numerically differentiating the position. This involves calculating the position at two closely spaced points in time and dividing the difference in position by the difference in time. This is a forward difference method.
Here's a breakdown for the Moon, as requested, and applicable to other bodies:
-
Forward step: The code calculates the Moon's position at the requested time tjd. Let's call this position pos1.
-
Backward step (not explicitly backward, but a second forward step): The code then calculates the Moon's position at a slightly later time, tjd + MOON_SPEED_INTV. MOON_SPEED_INTV is a small time increment defined as 0.00005 days (4.32 seconds). Let's call this position pos2.
-
Speed calculation: The speed is then approximated as (pos2 - pos1) / MOON_SPEED_INTV. This gives the average speed over the small interval. Because MOON_SPEED_INTV is positive, this is effectively a forward difference. There's no separate backward step to a time before tjd.
The positions are vectors in 3D space (longitude, latitude, and distance), so the subtraction and division are performed component-wise. This yields the speed in longitude, latitude, and radial distance.
Therefore, while the method involves two position calculations, it uses a single forward step to approximate the derivative. There isn't a separate calculation stepping backward in time. The second position calculation is a forward step, which, in combination with the first forward step, produces the required positions for the forward difference approximation of the speed.