top | item 44000123

(no title)

captaincrunch | 9 months ago

This is fast, READABLE, and accurate:

bool is_leap_year(uint32_t y) { // Works for Gregorian years in range [0, 65535] return ((!(y & 3)) && ((y % 25 != 0) || !(y & 15))); }

discuss

order

andrepd|9 months ago

This impl is mentioned in TFA.. It's much slower and includes branches.

hoten|9 months ago

I'd expect even without optimizations on, there wouldn't be branches in the output for that code.

windward|9 months ago

>READABLE

Great. It will be useful for the exhaustive tests of the faster version.

kragen|9 months ago

You commented out your entire function body and the closing }. Also, on 32-bit platforms, it doesn't stop working at 65535.

captaincrunch|9 months ago

just a formatting issue on my side, there were \n.