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

Can math.atan2 return INF?

On Wed, Jun 22, 2016, at 11:34, Ben Bacarisse wrote:
> Steven D'Aprano <steve at pearwood.info> writes:
> > 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

In C, the result of atan2(0, 0) [for any sign of zero] may be
implementation-dependent: "A domain error may occur if both arguments
are zero." In CPython, though, they're explicitly handled as special
cases by the m_atan2 function. The results match that of the x87 FPATAN
instruction, and presumably the IEEE standard (the same results are
prescribed in the IEC 60559 appendix of the C standard)

http://www.charlespetzold.com/blog/2008/09/180741.html mentions Intel's
rationale (in short, it's because 0+0j is a real number).