Unexpected NANs in complex arithmetic

Chris Angelico rosuav at gmail.com
Wed Jun 22 02:30:49 EDT 2016

On Wed, Jun 22, 2016 at 4:17 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Wednesday 22 June 2016 13:54, Dan Sommers wrote:
>> By the time Python returns a result for inf+3j, you're already in
>> trouble (or perhaps Python is already in trouble).
> I don't see why. It is possible to do perfectly sensible arithmetic on INFs.

Technically, arithmetic on INF is a short-hand for a limit. What is
inf+1? Well, it's the limit of x+1 as x tends toward +∞, which is ∞.
So inf+1 evaluates to inf.

>>> inf = float("inf")
>>> inf+1

What's 5-inf? Same again - the limit of 5-x as x tends toward +∞.
That's tending in the opposite direction, so we get infinity the other

>>> 5-inf

So it's not really "doing arithmetic on infinity", as such. That said,
I'm not entirely sure why "inf+3j" means we're already in trouble -
Dan, can you elaborate? ISTM you should be able to do limit-based
arithmetic, just the same.


More information about the Python-list mailing list