Can math.atan2 return INF?

Ben Bacarisse ben.usenet at bsb.me.uk
Wed Jun 22 11:34:14 EDT 2016


Steven D'Aprano <steve at pearwood.info> writes:

> On Wed, 22 Jun 2016 04:01 am, Pierre-Alain Dorange wrote:
<snip>
>> I do not know under what circumstance atan2 can return NAN, atan2 taks 2
>> argument (y and x) and return the angle corresponding to y/x.
>> If x is 0.0, atan2 return 0.0 (do not try to make the division).
>
> py> math.atan2(NAN, 0)
> nan
>
> I think that the only way it will return a NAN is if passed a NAN.

That seems to be the case but I was a little surprised to find that

  >>> math.atan2(INF, INF)
  0.7853981633974483

I would have expected NaN since atan2(INF, INF) could be thought of as
the limit of atan2(x, y) which could be any value in the range.  And I'd
have guessed atan2(0, 0) would have been NaN too but

  >>> math.atan2(0, 0)
  0.0

-- 
Ben.


More information about the Python-list mailing list