[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can math.atan2 return INF?

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

> On Wed, 22 Jun 2016 04:01 am, Pierre-Alain Dorange wrote:
>> 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)

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)