Skip to content

Tweak atan2

Reference issue

Partially addresses #2597 (closed)

What does this implement/fix?

The corner cases of atan2 as documented by https://en.cppreference.com/w/cpp/numeric/math/atan2 are numerous. However, most of these can be handled by atan if the argument is conditioned properly. Consider bending two rules of arithmetic that otherwise produce indeterminant results:

  • 0 / 0 = 0
  • inf / inf = 1

If arg = y/x (with the sign applied), then atan(arg) will produce the correct results, which are then shifted to the appropriate quadrant. Strict equality comparisons also preserve nan arguments. This simplifies the implementation and avoids a lot of work already being performed by atan.

Additionally, atan2 is now present in numext (which uses std::atan2) and has a corresponding packet function patan2. scalar_atan2_op has been configured to reference either numext::atan2 or patan2 per Eigen convention.

Also, there was a weird bug in (at least in MSVC) that prevented binary_ops_test() from working correctly. Passing x and y as auto produced random garbage, causing the tests to fail. Changing it to const auto& fixed it.

Additional information

Edited by Charles Schlosser

Merge request reports

Loading