Can math.atan2 return INF?
Ben Bacarisse
ben.usenet at bsb.me.uk
Thu Jun 23 10:37:48 EDT 2016
Steven D'Aprano <steve at pearwood.info> writes:
> On Thu, 23 Jun 2016 05:17 am, Ben Bacarisse wrote:
>
>> pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes:
>>
>>> Ben Bacarisse <ben.usenet at bsb.me.uk> wrote:
>>>
>>>> >>> 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
>>>
>>> i'm not a math expert, but the limit of atan2 would be 45°, so pi/4
>>> radians (0,7854).
>>> As x,y are coordinates, the both infinite would tend toward 45°.
>>
>> The limit of atan2(x, x) is as you describe, but there is no reason to
>> pick that one case.
>
> Given:
>
> x = INF
> y = INF
> assert x == y
>
> there is a reason to pick atan2(y, x) = pi/4:
>
> Since x == y, the answer should be the same as for any other pair of x == y.
>
> It might not be a *great* reason, but it's a reason.
...provided you consider atan2(0, 0) == 0 to be a bug!
--
Ben.
More information about the Python-list
mailing list