Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that you can keep adding/subtracting numbers to a polar coord, but what if I want to be able to take a number and just convert it to its positive equivalent?

share|cite|improve this question
up vote 1 down vote accepted

I will assume you want $0 \leq \theta < 2\pi$, since $2\pi$ and $0$ are the same angle. This is the modulo operation.

You can write it as $x \operatorname{mod} 2\pi$, or express it via floor function $x-2 \pi \lfloor \frac{x}{2\pi} \rfloor$, which works for both positive and negative $x$. Warning: Some programming languages with floating point modulo operators will give you negative result for negative angle. You can fix that by a single check if (result < 0) then result += 2*pi.

Theorem: For any real $a,b$ such that $b>0$ there exists exactly one integer $q$ and real $r \in [0,b)$ such that $a=qb+r$.

share|cite|improve this answer

If your system has an Atan2 function, it will be done for you.

share|cite|improve this answer
atan2(theta) = new theta? – John Smith Jan 26 '12 at 19:20
I'm not sure this function does what I need it to. For instance, say I have theta = 6*pi. I should be able to extract 0 as an answer. If I have -7pi/2, I should be able to extract 3*pi/2 as an answer or something to that extent – John Smith Jan 26 '12 at 19:35
@JohnSmith: I was assuming you had $(x,y)$ coordinates and wanted the angle. If you already have an angle, some systems allow the mod function on real arguments: theta%(2pi) will give something in the range [0,2pi). Otherwise you can use integer division: c=int(theta/(2pi)); theta=theta-c*2pi – Ross Millikan Jan 26 '12 at 22:00

If I'm right you want a function to get an input of any real number and convert it to it's equivalent angle between $0<\theta< 2\pi$? here is pseudo code how I do it: $$ \begin{eqnarray}&\text{while}(\theta<0\text{ or }\theta > 2\pi\text{)} \\ &\text{if(}\theta > 0)\\ &&\theta := \theta - 2\pi\\ &else\\ &&\theta := \theta + 2\pi\\ \end{eqnarray}$$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.