It seems thatatan2(0,0)
in C is defined this way. Python just delegates the common trigonometric functions to the underlying C implementation, right?

- 119,623
- 25
- 170
- 301

- 1,396
- 1
- 15
- 21
2 Answers
The Python docs don't explicitly specify atan2(0, 0), but the CPython implementation goes to specific effort to ensure special cases follow C99 even if the underlying C library doesn't. This includes a code path that handles making atan2(0, 0) return 0.0:
if (Py_IS_INFINITY(x) || y == 0.) {
if (copysign(1., x) == 1.)
/* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
return copysign(0., y);
...
In general, functions provided in the math
module that correspond to C standard library functions are expected to match the C standard behavior. There are a few blanket statements to this effect, such as this one near the top of the docs:
This module is always available. It provides access to the mathematical functions defined by the C standard.
and this one near the bottom:
Behavior in exceptional cases follows Annex F of the C99 standard where appropriate.
although Annex F isn't the part of the standard that defines atan2.

- 260,549
- 28
- 431
- 505
-
Thanks. I really meant CPython, the other various implementations are not relevant to my needs. – Emanuel Landeholm Mar 07 '19 at 06:53
As @user2357112 said, docs do not specify this. If you need something well documented - use numpy.arctan2
- see Notes section in https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.arctan2.html

- 8,025
- 2
- 27
- 45