Skip to content

Instantly share code, notes, and snippets.

@ParadoxV5
Created July 1, 2026 19:59
Show Gist options
  • Select an option

  • Save ParadoxV5/8eaebb4a310e2c15c99b85f10a08dc9f to your computer and use it in GitHub Desktop.

Select an option

Save ParadoxV5/8eaebb4a310e2c15c99b85f10a08dc9f to your computer and use it in GitHub Desktop.
Leap Year checker with only 2 modulus division operators
#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