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
I don't think I understand what the issue was or what the fix was. Was it a language or system that cannot perform the division with truncation?
Let's say height and width are 320x214.
(these numbers are arbitrarily chosen)
The code was sizing it down by /2, so now it is 160 by 107.
Because the width being odd, it would display.
But:
if ($width%2) { $width = --$width; }
Hastily written out on the phone, but that was the fix. This was back with php 5.
Sorry, but this comment still doesn't make sense (or has typos).
For a strong typed language, an integer division should not cast to any other data type. Even assigning a float to an integer should not be allowed (that's why C is not really strongly typed). I think from the syntax it was PHP. If any of the dimensions were not divisible by 2, then the number changed from integer to float and it could cause an issue somewhere downstream the video processing pipeline.
I don't think it's reexporting a video or something, I think it's the embed bc it is a CMS. PHP 5 isn't that old so video in webpages isn't a novel idea.
But you're right. Can't halve a pixel.
Do note that PHP5 is old, predating HTML5. Browsers probably still struggle with malformed HTML and in the absence of any sane value, just crash. Also, who knows if it was even HTML. For all I know it could be a flash.
Fuck, I forgot about Flash. I didn't think it was that old. Odds are it's just some other internal video player tbh.
OP didn't say that the problem was with the change in type. I think the interesting part is the downstream issue: what failed when a float was given while an integer was expected?
You can't halve a pixel. Truncating would get around the issue but big issue is that you can't have a float as a video resolution. The browser should just truncate it regardless but the original code is flawed.
OPs fix essentially does the same thing.
Dude, this reminds me of my coworker who was setting up a network and was trying to figure out a subnet mask, and he said, "I am trying to find a subnet mask between /22 and /23."
He spent the entire day on it. I finally had to ask, and once he told me his goal, I of course asked, "how the fuck do you get half of a bit?"
Oh, the blood drained from his face. "Yeah, bro, that's CIDR."
How does this not make sense? I am spoon feeding this shit. Are you just vibe coding?
I think there are some versions of Python and/or PHP where the normal division operator silently promotes to IEEE floats, and you have to explicitly cast back to truncate/floor the value.