Skip to main content
replaced http://dsp.stackexchange.com/ with https://dsp.stackexchange.com/
Source Link

it's an approximation.

a better approximation is in this answerthis answer:

$$ \arctan(u) \approx \frac{u}{f(u^2)} \quad \quad -1 \le u \le 1 $$

where

$$ \begin{align} f(u^2)& = \sum\limits_{n=0}^{4} \ a_n \ u^{2n} \\ a_0 & = 1.0 \\ a_1 & = 0.33288950512027 \\ a_2 & = -0.08467922817644 \\ a_3 & = 0.03252232640125 \\ a_4 & = -0.00749305860992 \\ \end{align} $$

not as fast, but quite accurate. not bit-perfect accurate, but very accurate.

for atan2(), you need to put it in the correct tilted quadrant:

$$ \operatorname{atan2}(y,x) = \arg\{ x + j\,y \} = \begin{cases} \arctan\left(\frac{y}{x}\right) &\text{if } 0 < |y| \le x, \\ \frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } 0 < |x| \le y, \\ -\frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } y \le -|x| < 0, \\ \arctan\left(\frac{y}{x}\right) \pm \pi &\text{if } x \le -|y| < 0, \\ \text{undefined} &\text{if } x = 0 \text{ and } y = 0. \end{cases} $$

this will require two fixed-point divisions, but you can arrange it so that the result is always no greater than 1 in magnitude (the numerator is always smaller in magnitude than the denominator).

it's an approximation.

a better approximation is in this answer:

$$ \arctan(u) \approx \frac{u}{f(u^2)} \quad \quad -1 \le u \le 1 $$

where

$$ \begin{align} f(u^2)& = \sum\limits_{n=0}^{4} \ a_n \ u^{2n} \\ a_0 & = 1.0 \\ a_1 & = 0.33288950512027 \\ a_2 & = -0.08467922817644 \\ a_3 & = 0.03252232640125 \\ a_4 & = -0.00749305860992 \\ \end{align} $$

not as fast, but quite accurate. not bit-perfect accurate, but very accurate.

for atan2(), you need to put it in the correct tilted quadrant:

$$ \operatorname{atan2}(y,x) = \arg\{ x + j\,y \} = \begin{cases} \arctan\left(\frac{y}{x}\right) &\text{if } 0 < |y| \le x, \\ \frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } 0 < |x| \le y, \\ -\frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } y \le -|x| < 0, \\ \arctan\left(\frac{y}{x}\right) \pm \pi &\text{if } x \le -|y| < 0, \\ \text{undefined} &\text{if } x = 0 \text{ and } y = 0. \end{cases} $$

this will require two fixed-point divisions, but you can arrange it so that the result is always no greater than 1 in magnitude (the numerator is always smaller in magnitude than the denominator).

it's an approximation.

a better approximation is in this answer:

$$ \arctan(u) \approx \frac{u}{f(u^2)} \quad \quad -1 \le u \le 1 $$

where

$$ \begin{align} f(u^2)& = \sum\limits_{n=0}^{4} \ a_n \ u^{2n} \\ a_0 & = 1.0 \\ a_1 & = 0.33288950512027 \\ a_2 & = -0.08467922817644 \\ a_3 & = 0.03252232640125 \\ a_4 & = -0.00749305860992 \\ \end{align} $$

not as fast, but quite accurate. not bit-perfect accurate, but very accurate.

for atan2(), you need to put it in the correct tilted quadrant:

$$ \operatorname{atan2}(y,x) = \arg\{ x + j\,y \} = \begin{cases} \arctan\left(\frac{y}{x}\right) &\text{if } 0 < |y| \le x, \\ \frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } 0 < |x| \le y, \\ -\frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } y \le -|x| < 0, \\ \arctan\left(\frac{y}{x}\right) \pm \pi &\text{if } x \le -|y| < 0, \\ \text{undefined} &\text{if } x = 0 \text{ and } y = 0. \end{cases} $$

this will require two fixed-point divisions, but you can arrange it so that the result is always no greater than 1 in magnitude (the numerator is always smaller in magnitude than the denominator).

Source Link

it's an approximation.

a better approximation is in this answer:

$$ \arctan(u) \approx \frac{u}{f(u^2)} \quad \quad -1 \le u \le 1 $$

where

$$ \begin{align} f(u^2)& = \sum\limits_{n=0}^{4} \ a_n \ u^{2n} \\ a_0 & = 1.0 \\ a_1 & = 0.33288950512027 \\ a_2 & = -0.08467922817644 \\ a_3 & = 0.03252232640125 \\ a_4 & = -0.00749305860992 \\ \end{align} $$

not as fast, but quite accurate. not bit-perfect accurate, but very accurate.

for atan2(), you need to put it in the correct tilted quadrant:

$$ \operatorname{atan2}(y,x) = \arg\{ x + j\,y \} = \begin{cases} \arctan\left(\frac{y}{x}\right) &\text{if } 0 < |y| \le x, \\ \frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } 0 < |x| \le y, \\ -\frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) &\text{if } y \le -|x| < 0, \\ \arctan\left(\frac{y}{x}\right) \pm \pi &\text{if } x \le -|y| < 0, \\ \text{undefined} &\text{if } x = 0 \text{ and } y = 0. \end{cases} $$

this will require two fixed-point divisions, but you can arrange it so that the result is always no greater than 1 in magnitude (the numerator is always smaller in magnitude than the denominator).