Hacker News new | ask | show | jobs
by bee_rider 623 days ago
Are there cases where float could return a NaN or infinity, where you instead prefer the integer result? That seems a little odd to me.
2 comments

Most people would love their bank accounts to underflow.
Integer division by zero will raise an exception in most modern languages.

Integer overflow is more problematic. While some languages in some situations will raise exceptions, most don't. While it's easier to detect overflow that has already occurred with floats (though you'll usually have lost low-order bits long before you get infinity), it's easier to avoid overflow in the first place with integers.