2 ms·
The suggestion: function compareNumbers(a, b) { return a - b; } Can this not suffer from overflow/underflow?
by js2 11y ago
The suggestion:
function compareNumbers(a, b) {
return a - b;
}
Can this not suffer from overflow/underflow?
- gpvos 11y agoJavascript numbers are reals, not integers. If they become too large (positively or negatively), they become +Infinity or -Infinity.
- hajile 11y agoAll numbers in JS are floats. Overflow and underflow are represented as positive and negative infinity while the check itself looks for 0, greater than zero, less than zero. Both infinities qualify as greater or less than zero (respectively), so I don't believe this problem exists.