Zaz
Zaz

Reputation: 48799

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?

Upvotes: 0

Views: 850

Answers (2)

shx2
shx2

Reputation: 64328

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

Upvotes: 2

Zaz
Zaz

Reputation: 48799

Ahh, just after I posted this, I answered my own question:

It's because there's no way of knowing if the result should be +inf or -inf.

As an aside, the IEEE floating point standard does support positive and negative 0.

Upvotes: 0

Related Questions