[Numpy-discussion] incorrect behavior when complex number with zero imaginary part is multiplied by inf
pav at iki.fi
Fri Jan 28 10:23:09 EST 2011
Fri, 28 Jan 2011 11:49:34 +0100, Mark Bakker wrote:
> Yet when the imaginary part is zero (and it really is a real number),
> the imaginary part is nan:
> In : inf * (1+0j)
> Out: (inf+nan*j)
> That is not correct. It should really given (inf+0*j). (I know where it
> comes from, inf*0 is not defined, but in this case it is, as 1+0j is
> really a real number and inf is by definition real as well).
> If there is consensus I can file a ticket.
Both behaviors are accepted by the C99 standard: all combinations where
one entry is `+-inf` are equivalent to the complex infinity. gcc itself
returns `inf-1j*nan`. gfortran returns `inf+1j*nan`.
A good rationale for the present behavior is that there is no way to know
that 1+0j is supposed to be real; it could as well be a number too small
to represent (eg. result from an underflow in the imaginary part), in
which case `nan` is indeed the correct result.
More information about the NumPy-Discussion