NewsCrawler.org

A faster way to calculate the date of Easter

Ben Joffe's post describes a faster way to compute the date of Easter under the Gregorian rules. He calls it a side project for his work on optimising regional calendars, and notes that the speed would not matter in most real applications. For high-frequency trading, he suggests an in-memory lookup table may be the better choice. The Easter rules were set at the First Council of Nicaea in 325 AD and changed by Pope Gregory XIII in 1582, and the post covers the more complex Gregorian version.

The author says the code runs about twice as fast as a standard Easter function in a typical date library, and uses 5 multiplications where typical reference algorithms use 10 or more. Its accuracy range is about -11 million to +16 million years, so any date library that stores dates as a signed or unsigned 32-bit rata die[1] is covered.

A more readable version of the function is also given for readers who want the higher-level optimisations without the bit-level tricks. A variant in the C++ repository covers a range of -73,803,600 to 70,208,581. The post explains how the year modulo 19 steps, which relate to the Metonic cycle[2], can be computed with a single multiplication.

Read the original benjoffe.comDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page