SWI-Prolog / issues

Dummy repository for issue tracking
7 stars 3 forks source link

leap year bug in day_of_the_year/2 #80

Open Shyam-Has-Your-Anomaly-Mitigated opened 5 years ago

Shyam-Has-Your-Anomaly-Mitigated commented 5 years ago

I am following the official steps.

Step 01.

linux$ swipl -v
SWI-Prolog version 7.6.4 for i386

Step 10.

I visited Rosetta Code, and then discovered this bug.

?- findall(Y, (between(1700,2000,Y), 0 is Y mod 100, day_of_the_year(date(Y,12,31),366)), L).
L = [1700, 1800, 1900, 2000].

Wikipedia says:

For example, the years 1700, 1800, and 1900 are not leap years, but the year 2000 is.[5]

Matt Parker explains leap years from many perspectives; including historical, mathematical, philosophical, and humourous.

JanWielemaker commented 5 years ago

Thanks. I fear this is because the computation eventually uses the C library for several of the date properties and this is probably only guaranteed to work after the Unix epoch (1970). Might be possible to fix this by falling back to the libtai functions that have less functionality but span a longer range.

I'm afraid I leave in on the stack for now.

Shyam-Has-Your-Anomaly-Mitigated commented 5 years ago

𝓗𝓮𝓵𝓵𝓸 𝓙𝓪𝓷,

𝓓𝓸𝓮𝓼 𝓽𝓱𝓪𝓽 𝓶𝓮𝓪𝓷 𝓽𝓱𝓮 𝓜𝓲𝓵𝓵𝓮𝓷𝓷𝓲𝓾𝓶 𝓫𝓾𝓰 𝓪𝓵𝓼𝓸 𝓮𝔁𝓹𝓵𝓪𝓲𝓷𝓼 𝓫𝓮𝔂𝓸𝓷𝓭 2000? 𝓘 𝓽𝓱𝓸𝓾𝓰𝓱𝓽 𝓲𝓽 𝔀𝓪𝓼 𝓳𝓾𝓼𝓽 𝓪 𝓹𝓻𝓸𝓫𝓵𝓮𝓶 𝓸𝓯 𝓰𝓸𝓲𝓷𝓰 𝓯𝓻𝓸𝓶 1999 𝓽𝓸 2000, 𝔀𝓱𝓮𝓻𝓮 =(1900,2000);==(1900,2000);=:=(1900,2000);_.

?- findall(Y, (between(2000,2400,Y), 0 is Y mod 100, day_of_the_year(date(Y,12,31),366)), L). L = [2000, 2100, 2200, 2300, 2400].

𝓘 𝓱𝓪𝓿𝓮 𝓭𝓲𝓼𝓬𝓸𝓿𝓮𝓻𝓮𝓭 𝓶𝓸𝓻𝓮 𝓽𝓮𝓶𝓹𝓸𝓻𝓪𝓵 𝓪𝓷𝓸𝓶𝓪𝓵𝓲𝓮𝓼; 𝓪𝓹𝓹𝓪𝓻𝓮𝓷𝓽𝓵𝔂 𝓽𝓱𝓮 𝓜𝓲𝓵𝓵𝓮𝓷𝓷𝓲𝓾𝓶 𝓫𝓾𝓰 𝓲𝓼 𝓪 𝓽𝓮𝓬𝓱𝓷𝓸𝓵𝓸𝓰𝓲𝓬𝓪𝓵 𝓰𝓵𝓸𝓫𝓪𝓵 𝓬𝓪𝓽𝓪𝓼𝓽𝓻𝓸𝓹𝓱𝓲𝓬 𝓻𝓲𝓼𝓴!

🖖 𝓛𝓲𝓿𝓮 𝓛𝓸𝓷𝓰 ∧ 𝓟𝓻𝓸𝓼𝓹𝓮𝓻 \∨/, 𝓐𝓰𝓮𝓷𝓽 𝓢. 🕴 𝓜𝓲𝓰𝓻𝓪𝓽𝓲𝓷𝓰 𝓘𝓷𝓯𝓮𝓼𝓽𝓲𝓿𝓮 𝓑𝓾𝓰𝓼!!