For greater/less than operators, normal operators (instead of comparison function calls) can be in these cases:
The operator is lessThan, the left input can be a number or NaN, and the right input is a number that can't be NaN
The operator is greaterThan, the left input is a number that can't be NaN, and the right input can be a number or NaN
This can be done because string comparisons with numbers and NaN in these scenarios will always return false (for example, "NaN" < "10000" is false, which is the same as NaN < 10000)
If this is not done, then the compareLessThanSlow path is taken for each comparison with these values, assuming they include NaN
I've now realized that, by using !(val1 >= val2), and similarly with <=, you can completely remove all function calls for number + number or NaN comparisons.
For greater/less than operators, normal operators (instead of comparison function calls) can be in these cases:
lessThan
, the left input can be a number or NaN, and the right input is a number that can't be NaNgreaterThan
, the left input is a number that can't be NaN, and the right input can be a number or NaNThis can be done because string comparisons with numbers and NaN in these scenarios will always return false (for example,
"NaN" < "10000"
is false, which is the same asNaN < 10000
) If this is not done, then thecompareLessThanSlow
path is taken for each comparison with these values, assuming they include NaN