Atan2 vs fabs


#1

The code atan2(sin(x),cos(x)) achieves the same computation as fabs(x,2*pi()). The manual warns that fabs() can induce sampling issues; would the same issues apply to the atan2 version?


#2

Warning is due to possible discontinuity in gradient. The same applies for any function which may produce discontinuity in gradient.


#3

Gotcha. I have nil training in calculus; presumably atan2(sin(x),cos(x)) has a discontinuous gradient?


#4

At n*pi, the derivative is undefined because the function is discontinuous.


#5

Gotcha, thanks @yizhang