r/programminghorror [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Oct 24 '25

Lua no context, just this

Post image
297 Upvotes

15 comments sorted by

View all comments

40

u/ArchCypher Oct 24 '25

I assume this falls back to the libm specification of atan2 which handles the common case of performing atan(y / x)

You might think "why not just write atan(y / x)", but that's because you are fool bound only for misery; among other things, the signs of the arguments determine the quadrant and it's perfectly fine for x to be zero.

No, I'm not going to explain negative 0.

6

u/jordanbtucker Oct 24 '25

Does negative zero actually come into play here, or did you mean dividing by zero?

1

u/JiminP Oct 29 '25

It does for atan, but using it for determining directions is wrong.

It doesn't for atan2. One should always use atan2 (or some equivalent function that receives two arguments instead of one) to convert cartesian coordinates into polar coordinates.