3 ms·
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.
by bee_rider 2y 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.
- kbolino 2y agoInteger 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.
- estebarb 2y agoMost people would love their bank accounts to underflow.