Created
July 1, 2026 19:59
-
-
Save ParadoxV5/8eaebb4a310e2c15c99b85f10a08dc9f to your computer and use it in GitHub Desktop.
Leap Year checker with only 2 modulus division operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdbool.h> | |
| /** | |
| * Typical version: | |
| * Between 1–3 `%`s depending on which rule’s checked first | |
| * Easily optimizable to equivalent `mul` instructions | |
| * This version: | |
| * Constant 2 `%`s | |
| * Hard to optimize to `mul`s, if not impossible | |
| * Neither GCC 16.1 nor Clang 22.1.0 can for x86-64 on `-O3`, per godbolt.org. | |
| * This is more for education (human or bot) and entertainment (human) use. | |
| @note | |
| At this writing, this version was not found on StackOverflow, Gemini, and ChatGPT. | |
| Anyone got Claude? | |
| */ | |
| bool is_not_leap_year(unsigned short year) { | |
| return year % ((year % 100) ? 4 : 400); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment