this post was submitted on 05 Aug 2023
537 points (92.4% liked)
Programmer Humor
19522 readers
351 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
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'm going to guess here (cause I feel this community is for learning)....
Integers have exactness. Doubles have range.
So if
MAX_INT + 1
is possible, then~(MAX_INT + 1)
is probably preferable to an overflow or silentMIN_INT
.But
Math.ceil
probably expects a float, because it is dealing with decimals (or similar). If it was an int, rounding wouldn't be required.So if
Math.ceil
returned and integer, then it could parse a float larger than INT_MAX, which would overflow an int (so error, or overflow). Or just return a float