I'm surprised that
>>> import math
>>> 1**math.nan
1.0
And while we are at it, also that
>>> 0j**math.nan
0j
I didn't find any other examples. Is there a reason or some logic I've missed that makes this the right choice? Or is this a slip?
I was expecting nan
. As for every other number except 1
or 0j
.
Edit 1: Thanks to jedwards's comment below I have a reference. But I still don't understand why. Why was this decided as the standard? Also, couldn't find reference to 0j**mat.nan
...
Edit 2: So following the answers below and some other stuff, the logic may be this one: Any calculation involving nan
should return nan
unless the calculation is always returning the same answer regardless of arguments. In such cases, the fact that we have nan
as an argument should not affect the result and we should still get the fixed answer.
This certainly explains 1**math.nan
and math.nan**0
. This also explains why 0**math.nan
gives nan
and not 0
(since 0**n
is 0
for all but when n=0
where it results with 1
), and might be stretched to cover why math.nan*0
is nan
if we agree that the argument need not be finite.
But if this is the logic behind the scene, then 0j**math.nan
should have been nan
, since 0j**n
is 0
for all n
's except n=0
where 0j**0
is 1
. So... does 0j**math.nan
have different reasoning? or is it a problem in implementation?