MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / computus

Function computus

contents/computus/code/c/gauss_easter.c:3–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <stdio.h>
2
3char *computus(int year, int servois, char *out, size_t out_size) {
4 // Year's position on the 19 year metonic cycle
5 int a = year % 19;
6
7 // Century index
8 int k = year / 100;
9
10 //Shift of metonic cycle, add a day offset every 300 years
11 int p = (13 + 8 * k) / 25;
12
13 // Correction for non-observed leap days
14 int q = k / 4;
15
16 // Correction to starting point of calculation each century
17 int M = (15 - p + k - q) % 30;
18
19 // Number of days from March 21st until the full moon
20 int d = (19 * a + M) % 30;
21
22 // Returning if user wants value for Servois' table
23 if (servois) {
24 snprintf(out, out_size, "%d",(21 + d) % 31);
25 return out;
26 }
27
28 // Finding the next Sunday
29 // Century-based offset in weekly calculation
30 int N = (4 + k - q) % 7;
31
32 // Correction for leap days
33 int b = year % 4;
34 int c = year % 7;
35
36 // Days from d to next Sunday
37 int e = (2 * b + 4 * c + 6 * d + N) % 7;
38
39 // Historical corrections for April 26 and 25
40 if ((d == 29 && e == 6) || (d == 28 && e == 6 && a > 10)) {
41 e = -1;
42 }
43
44 if ((22 + d + e) > 31) {
45 snprintf(out, out_size, "April %d", d + e - 9);
46 } else {
47 snprintf(out, out_size, "March %d", 22 + d + e);
48 }
49
50 return out;
51}
52
53int main() {
54 char tmp1[9], tmp2[9];

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected