Complex.js
Complex.js copied to clipboard
Should infinite values be considered equal?
Currently: new Complex(Infinity).equals(Infinity) === false.
For reference:
In JavaScript: Infinity === Infinity is true
In Matlab both Inf == Inf and (Inf + Inf*i) == (Inf + Inf*i) aretrue
In Wolfram 'Infinity == Infinityistrueand it refuses to answerComplexInfinity == ComplexInfinity`
The c++ standard complex library compares the real and imaginary parts of the number.
Comparing re and im is done here as well, but not in a == manner but comparing against a rounding-error ignoring small epsilon. And since Inf-Inf =Inf > eps it is currently false. We could either add a special infinity check here or we keep it like this. I mean it's a philosophical question and totally depends on how you see infinity. When you say there are infinitely many infinites, then the current behavior is right. If you see it as a symbol comparision then we should follow other implementations