Can math.atan2 return INF?

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Tue Jun 21 14:32:48 EDT 2016


pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes:

> Steven D'Aprano <steve at pearwood.info> wrote:
>
>> Are there any circumstances where math.atan2(a, b) can return an infinity?
>> 
>> I know it will return a NAN under some circumstances.
>
> atan or atan2 can't return INFINITE, it was the arc tangent of a
> value, then arc tangent can only be between -PI and +PI (is was an
> angle).
>
> 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).

It seems to return NaN when either argument is NaN. It seems to return
finite values when either argument is Inf or -Inf, and negative zeroes
lead to different but finite answers.

Wikipedia says ata2(0,0) is considered undefined traditionally and in
symbolic maths but otherwise most computer implementations define it.
Python seems to produce +-0.0 and +-pi for variously signed zeroes.

I didn't see any mention of it ever being infinite, which makes sense
given that arcus functions are supposed to return angles. The extreme
case seemed to be the inclusion of -pi as a possible value.

(I know nothing, I was just curious enough to play with this a bit.)



More information about the Python-list mailing list