# How does a calculator calculate the sine, cosine, tangent using just a number?

• Sine $$θ\theta$$ = opposite/hypotenuse
• Cosine $$θ\theta$$ = adjacent/hypotenuse
• Tangent $$θ\theta$$ = opposite/adjacent

In order to calculate the sine or the cosine or the tangent I need to know $$33$$ sides of a right triangle. $$22$$ for each corresponding trigonometric function. How does a calculator calculate the sine, cosine, tangent of a number (that is actually an angle ?) without knowing any sides?

## Answer

Calculators either use the Taylor Series for $$sin/cos\sin / \cos$$ or the CORDIC algorithm. A lot of information is available on Taylor Series, so I’ll explain CORDIC instead.

The input required is a number in radians $$θ\theta$$, which is between $$−π/2-\pi / 2$$ and $$π/2\pi / 2$$ (from this, we can get all of the other angles).

First, we must create a table of $$arctan2−k\arctan 2^{-k}$$ for $$k=0,1,2,…,N−1k=0,1,2,\ldots, N-1$$. This is usually precomputed using the Taylor Series and then included with the calculator. Let $$ti=arctan2−it_i = \arctan 2^{-i}$$.

Consider the point in the plane $$(1,0)(1, 0)$$. Draw the unit circle. Now if we can somehow get the point to make an angle $$θ\theta$$ with the $$xx$$-axis, then the $$xx$$ coordinate is the $$cosθ\cos \theta$$ and the $$yy$$-coordinate is the $$sinθ\sin \theta$$.

Now we need to somehow get the point to have angle $$θ\theta$$. Let’s do that now.

Consider three sequences $${xi,yi,zi}\{ x_i, y_i, z_i \}$$. $$ziz_i$$ will tell us which way to rotate the point (counter-clockwise or clockwise). $$xix_i$$ and $$yiy_i$$ are the coordinates of the point after the $$ii$$th rotation.

Let $$z0=θz_0 = \theta$$, $$x0=1/A40≈0.607252935008881x_0 = 1/A_{40} \approx 0.607252935008881$$, $$y0=0y_0 = 0$$. $$A40A_{40}$$ is a constant, and we use $$4040$$ because we have $$4040$$ iterations, which will give us $$1010$$ decimal digits of accuracy. This constant is also precomputed1.

Now let:

$$zi+1=zi−diti z_{i+1} = z_i - d_i t_i$$
$$xi+1=xi−yidi2−i x_{i+1} = x_i - y_i d_i 2^{-i}$$
$$yi=yi+xidi2−i y_i = y_i + x_i d_i 2^{-i}$$
$$di=1 if zi≥0 and -1 otherwise d_i = \text{1 if } z_i \ge 0 \text{ and -1 otherwise}$$

From this, it can be shown that $$xNx_N$$ and $$yNy_N$$ eventually become $$cosθ\cos \theta$$ and $$sinθ\sin \theta$$, respectively.

1: $$AN=N−1∏i=0√1+2−2iA_N = \displaystyle\prod_{i=0}^{N-1} \sqrt{1+2^{-2i}}$$

Attribution
Source : Link , Question Author : themhz , Answer Author : Rajdeep Sindhu