Urgent.News

What's breaking now, across thousands of outlets.

Tech

A faster Easter date function

This article details a fast algorithm for calculating the date of Easter based on the Gregorian calendar rules. The First Council of Nicaea established the foundation for Easter in 325 AD, which was later modified by Pope Gregory XIII in 1582. The Church of England began observing the new date in 1753, while Eastern/Orthodox churches still follow the original rules.

The new Gregorian Easter function, presented in this article, is significantly faster than typical alternatives found in date libraries. The function's speed is attributed to its simplicity, using only five multiplications compared to ten or more in standard algorithms. Additionally, the function has a broad accuracy range, spanning approximately -11m to +16m years, which covers all signed or unsigned 32-bit rata die dates.

The function contains more terms than traditional Easter functions, but its compiled assembly is smaller. The article explains the main tricks used in the function, including adding a SHIFT value to the input, which aligns the century and increases the coverage range of the Easter pattern. Another trick is a clever use of MOD 30, which is different from the modulo operator in C for negative numbers.

Finally, the article discusses the use of a single multiplication for computing year % 19 and how to eliminate the % 7 term in the final result.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at benjoffe.com →

More in Tech

More from Tuesday 10 November →