# Did I derive a function for finding the angle of a complex number?

When presented with a complex # written in rectangular form (x + j*y), w/ the goal of converting it to polar form, the following 2 relationships are used:

• r = √ ( x^2 + y^2 )
• θ = tan-1(y/x)

The equation for r works just fine but the one for θ breaks down w/ negative inputs... so either you do as I do and use whichever trig relationship makes the most sense for the given quad, or you can continue using tan but you must abide by quad dependent contingencies:

• θ = tan-1(y/x) + 180, x < 0, y < 0
• θ = tan-1(y/x) + 180, x < 0, y > 0
• θ = tan-1(y/x) + 360, x > 0, y < 0
• θ = tan-1(y/x), x > 0, y > 0

I decided to throw all of these contingencies into a single package and I would like your feedback on it:

θ = tan-1(y/x) + (1/2)((x/|x|) - 1)(180) + (1/2)((x/|x|) + 1)(-1/2)((y/|y|) - 1)(360)

Which translates to... if x < 0 ADD 180, else if x>0 AND y<0 ADD 360.

And, after simplifying, it looks like this:

θ = tan-1(y/x) - 90[(y/|y|)((x/|x|) + 1) - 2]

As far as feedback goes, I have a couple of questions:

• Is there an equation already like this?
• If so, is it simpler than mine?
• If no, you might come up with a simpler approach! Please share it w/ me if so (:! I think it would be cooler if it didn't require absolute value operations but I couldn't figure out any other way to get 1 for pos #s and -1 for neg #s.
• Did I make any mistakes? I entered complex numbers for each quad and received the correct outputs. Let me know if you spot any errors.
• You'd be better off writing a piecewise function with the canonical $\arctan$ function. You don't realize it, but you're doing that with the $\arctan$ (to begin with) and especially the absolute value functions. Sep 10, 2018 at 7:11
• Please read this MathJax tutorial, which explains how to typeset mathematics on this site. Sep 10, 2018 at 7:16
• What if $x$ or $y$ is zero? And what do you need the formula for? Is numeric stability an issue? Note also that the standard libraries of many programming languages have a atan2(y, x) function which does the job. Sep 10, 2018 at 7:37
• @Jared The whole point in my quest to derive the single function was to eliminate the need for the piece wise function as I don't think they should be used when unnecessary. How would I be better off writing a piecewise function if I already wrote it (to begin with)? Sep 10, 2018 at 7:53
• @N.F.Taussig Thank you, I will read that and use it from now on. Sep 10, 2018 at 7:54