this post was submitted on 05 Aug 2023
540 points (92.5% liked)
Programmer Humor
28142 readers
407 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 2 years 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 + 1is possible, then~(MAX_INT + 1)is probably preferable to an overflow or silentMIN_INT.But
Math.ceilprobably expects a float, because it is dealing with decimals (or similar). If it was an int, rounding wouldn't be required.So if
Math.ceilreturned 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