I want to transfer to C#, a function that computes the phasor angle of an expression from MATLAB, angle()
. I found that angle(x+yi)=atan2(y,x)
but here comes my problem, I have a square root that depending on the values I give it is either positive or negative. But, in MATLAB if the sqrt function gets a negative, it returns an imaginary, unlike C# where it returns NaN.
So, how can I make the two codes give the same result?
ie MATLAB:
angle(a*1i-sqrt(expression))
C#:
Mathf.Atan2(a,-sqrt(expression))
(what i do, and i think is wrong)