In Matlab when obtaining the inverse tangent of $-\pi$ in radians, the results vary between small changes in decimal points:
atan2(sin(-3.141592653589793), cos(-3.141592653589793)) = -3.141592653589793
atan2(sin(-3.141593), cos(-3.141593)) = 3.141592307179587
atan2(sin(-3.14159), cos(-3.14159)) = -3.141590000000000
atan2(sin(-3.1416), cos(-3.1416)) = 3.141585307179587
Could anyone please explain why the sign change occurs between -3.14 and +3.14 ?
Let $\varepsilon$ be very small number, such that $\varepsilon$ > 0
We know that
tan($\frac{\pi}{2}$ + $\varepsilon$) = -$\infty$
tan($\frac{\pi}{2}$ - $\varepsilon$) = +$\infty$
I hope you know why sign change occurs here.
Use similar analogy
Now coming to your question, this happens because range of atan2 is [-${\pi}$,${\pi}$]
So even the slightest change at boundary causes its value to wrap around, reach the other end and continue from there.