Pure function given strictly equal arguments yielding non-strictly equal results

后端 未结 6 624
执念已碎
执念已碎 2021-01-04 12:59

Below is a pure function f for which f(a) !== f(b) despite a === b (notice the strict equalities) for some values of a<

6条回答
  •  一生所求
    2021-01-04 13:46

    this behaviour is perfectly ok, because, in mathematical theory, -0 === +0 is true, and 1/(-0) === 1/(+0) is not, because -inf != +inf

    EDIT: although I am really surprised that javascript can in fact handle these kinds of mathematical concepts.

    EDIT2: additionally, the phenomenon you described is completely based on the fact, that you divide by zero from which you should expect at least some strange behaviour.

提交回复
热议问题