this post was submitted on 22 Jul 2025
407 points (98.1% liked)

Programmer Humor

25253 readers
1159 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

founded 2 years ago
MODERATORS
 

I don't think that casting a range of bits as some other arbitrary type "is a bug nobody sees coming".

C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

That's why I love C++

(page 2) 50 comments
sorted by: hot top controversial new old
[–] goatinspace@feddit.org 5 points 4 days ago

Don't be average

[–] Shanmugha@lemmy.world 2 points 3 days ago

Aand what is wrong with that?

[–] Opisek@lemmy.world 2 points 2 days ago* (last edited 2 days ago)

The problem is that it's undefined behavior. Quake fast inverse square root only works before the types just happen to look that way. Because the floats just happens to have that bit arrangement. It could look very different on other machines! Nevermind that it's essentially always exactly the same on most architectures. So yeah. Undefined behavior is there to keep your code usable even if our assumptions about types and memory change completely one day.

load more comments
view more: ‹ prev next ›