this post was submitted on 19 Nov 2026
196 points (99.5% liked)
Programmer Humor
34233 readers
1427 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
- If the mod doesn't find it funny, you're banned. Ha-ha!... For real: do not use the community for "statements". There are other places for such content. Keep it chill and funny.
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Ok, I understand the issue but I don't understand your embarrassment from it. You didn't write the initial bug.
Btw, a faster way to check if a value is even is to just do a bitwise AND on bit 0 (if it is an integer, though it needs to be an integer for modulus to work anyways).
In many languages it looks like:
if ( val & 1 ) { \ it is odd }
Division is a multi-cycle operation but bitwise comparisons are simple enough to be done in a single cycle, or could even be thrown on to instructions as a free extra that doesn't add any extra cycles (eg any instruction with a bit mask, though it depends on the implementation as to whether it's done for 0 extra cycles or more).
Doesn't really matter for a one off operation like halving the value of video display parameters, but if you have a loop that needs to check a lot of them, the bitwise and will pull ahead.
And if you're thinking "well we need to divide by 2 anyways and the modulus is available from that operation as long as the compiler sees it should save the result and the modulus", a bitwise shift right (non-circular) of 1 is also way faster than divide by 2.
Both of these can also be generalized for any power of 2, if necessary.
Most compilers worth their salt will optimize a modulo evenness check to a bit operation anyways
Dude, the embarrassment was because I was the new kid.
It was pointed out. It was a bug that had plagued the company. Thought this was all explained.