## ◆ atan2()

 IEEEValue boost::simd::atan2 ( IEEEValue const & y, IEEEValue const & x )

This function object returns the quadrant aware atan2 function.

Notes
• For any real arguments x and y not both equal to zero, atan2(y, x) (be aware of the parameter order) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y).
• It is also the angle in $$[-\pi,\pi[$$ for which $$x/\sqrt{x^2+y^2}$$ and $$y/\sqrt{x^2+y^2}$$ are respectively the sine and the cosine.
• Following IEEE norms, we should have:

• If y is $$\pm0$$ and x is negative or -0, $$\pm\pi$$ is returned
• If y is $$\pm0$$ and x is positive or +0, $$\pm0$$ is returned
• If y is $$\pm\infty$$ and x is finite, $$\pm\pi/2$$ is returned
• If y is $$\pm\infty$$ and x is $$-\infty$$, $$\pm3\pi/4$$ is returned
• If y is $$\pm\infty$$ and x is $$+\infty$$, $$\pm\pi/4$$ is returned
• If x is $$\pm0$$ and y is negative, $$-\pi/2$$ is returned
• If x is $$\pm0$$ and y is positive, $$+\pi/2$$ is returned
• If x is $$-\infty$$ and y is finite and positive, $$+\pi$$ is returned
• If x is $$-\infty$$ and y is finite and negative, $$-\pi$$ is returned
• If x is $$+\infty$$ and y is finite and positive, +0 is returned
• If x is $$+\infty$$ and y is finite and negative, -0 is returned
• If either x is Nan or y is Nan, Nan is returned

The pedantic_ decorator ensures all these conditions, but the regular version (no decorator) will return a NaN if x and y are both either null or infinite, result which in fact is not more absurd than the IEEE choices. It will be conforming in all other cases.

Decorators
• pedantic_ ensures the respect of all IEEE limits
atan, atand, atanpi
Example:
#include <boost/simd/trigonometric.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/function/reverse.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = {1.0f, 2.0f, -1.0f, 0.5f};
pack_ft qf = bs::reverse(pf);
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qf = " << qf << '\n'
<< "-> bs::atan2(pf, qf) = " << bs::atan2(pf, qf) << '\n';
float xf = 2.0f, yf = 3.0f;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "-> bs::atan2(xf, yf) = " << bs::atan2(xf, yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1, 0.5)
<- qf = (0.5, -1, 2, 1)
-> bs::atan2(pf, qf) = (1.10715, 2.03444, -0.463648, 0.463648)
---- scalar
<- xf = 2
<- yf = 3
-> bs::atan2(xf, yf) = 0.588003