English

Euclidean Affine Functions and Applications to Calendar Algorithms

Data Structures and Algorithms 2025-01-08 v1 Discrete Mathematics

Abstract

We study properties of Euclidean affine functions (EAFs), namely those of the form f(r)=(αr+β)/δf(r) = (\alpha\cdot r + \beta)/\delta, and their closely related expression f˚(r)=(αr+β)%δ\mathring{f}(r) = (\alpha\cdot r + \beta)\%\delta, where rr, α\alpha, β\beta and δ\delta are integers, and where // and %\% respectively denote the quotient and remainder of Euclidean division. We derive algebraic relations and numerical approximations that are important for the efficient evaluation of these expressions in modern CPUs. Since simple division and remainder are particular cases of EAFs (when α=1\alpha = 1 and β=0\beta = 0), the optimisations proposed in this paper can also be appplied to them. Such expressions appear in some of the most common tasks in any computer system, such as printing numbers, times and dates. We use calendar calculations as the main application example because it is richer with respect to the number of EAFs employed. Specifically, the main application presented in this article relates to Gregorian calendar algorithms. We will show how they can be implemented substantially more efficiently than is currently the case in widely used C, C++, C# and Java open source libraries. Gains in speed of a factor of two or more are common.

Keywords

Cite

@article{arxiv.2102.06959,
  title  = {Euclidean Affine Functions and Applications to Calendar Algorithms},
  author = {Cassio Neri and Lorenz Schneider},
  journal= {arXiv preprint arXiv:2102.06959},
  year   = {2025}
}

Comments

24 pages, 4 figures

R2 v1 2026-06-23T23:07:56.627Z