It seems thatatan2(0,0)
in C is defined this way. Python just delegates the common trigonometric functions to the underlying C implementation, right?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With