Search code examples
pythondivide-by-zero

Why does 1/inf == 0 but 1/0 != inf?


In general, 1/a = b ⟺ 1/b = a, so if we're letting the reciprocal of infinity be 0, the reciprocal of 0 should be infinity.

It seems strange for Python to use the limit for 1/inf but not for 1/0. What is the rationale behind this decision?


Solution

  • Because 1/0 can be either +inf (positive) or -inf (negative). 1/inf can only be 0.