How Computers Calculate Trigonometric Functions
In 1972, Hewlett-Packard released the HP-35, the first handheld scientific calculator. It could compute sine, cosine, tangent and logarithms at the press of a key, and it helped make the slide rule obsolete.
Its processor couldn't even multiply quickly. So how did it compute sin(37°)? With an algorithm called CORDIC, invented in 1959 for the navigation computer of a supersonic bomber, which calculates trigonometry using nothing but additions and bit shifts.
Today's computers use a few different strategies. None of them look up a giant table of sines.
You Only Need to Compute Sine for Small Angles
Sine and cosine are defined for every angle, but thanks to symmetry, a computer only needs to evaluate them accurately between 0 and 45° (0 to π/4 radians).
Every other angle can be folded into that range:
sin(θ + 360°) = sin θ (periodicity)
sin(180° − θ) = sin θ (symmetry)
sin(90° − θ) = cos θ (co-function)
sin(−θ) = −sin θ (odd function)
For example, sin(150°) = sin(30°), and sin(70°) = cos(20°). Find these reductions with the reference angle calculator.
Method 1: Taylor Series
For angles in radians, sine and cosine can be written as infinite polynomials:
sin x = x − x³/3! + x⁵/5! − x⁷/7! + …
cos x = 1 − x²/2! + x⁴/4! − x⁶/6! + …
For small x, the terms shrink very quickly because the factorials in the denominators grow so fast.
Example: sin(30°), with 30° = π/6 ≈ 0.5235988 radians:
x = 0.5235988
x³/6 = 0.0239246
x⁵/120 = 0.0003280
sin x ≈ 0.5235988 − 0.0239246 + 0.0003280 = 0.5000021
Just three terms give 0.50000, correct to five decimal places. That's why folding angles down to 45° matters: for small x, few terms are needed. Convert degrees with degrees to radians.
Modern math libraries use carefully tuned versions of this approach: polynomial approximations over small intervals, sometimes combined with a small table of precomputed values near nearby angles, with extra care to keep rounding errors below the last bit.
Method 2: CORDIC, Trig With Only Shifts and Adds
In 1959, engineer Jack E. Volder at Convair developed CORDIC (COordinate Rotation DIgital Computer) for the navigation system of the B-58 bomber. Its hardware needed fast trigonometry without expensive multiplication circuits.
The idea: rotate a vector toward the target angle using a fixed sequence of special angles, whose tangents are powers of two:
| Step i | Angle arctan(2⁻ⁱ) |
|---|---|
| 0 | 45° |
| 1 | 26.565° |
| 2 | 14.036° |
| 3 | 7.125° |
| 4 | 3.576° |
| 5 | 1.790° |
Each angle is roughly half the previous one. At each step, rotate toward the remaining angle, either clockwise or counterclockwise:
x_new = x − d · y · 2⁻ⁱ
y_new = y + d · x · 2⁻ⁱ
z_new = z − d · arctan(2⁻ⁱ)
Here d is +1 or −1. Multiplying by 2⁻ⁱ is just a binary shift, which is very cheap in hardware. After n steps, the vector (x, y) points at the target angle, scaled by a known constant (about 0.6073 for many steps). Scale it back and you get cos θ and sin θ.
Each iteration adds roughly one bit of accuracy. Sixteen steps give about four to five decimal digits. CORDIC powered early calculators like the HP-35 and is still used in FPGAs, microcontrollers and signal-processing chips. Check the table's angles with the arc tangent calculator.
Method 3: Lookup Tables With Interpolation
Before computers, people used printed trigonometric tables with values at regular intervals, estimating in between. Some embedded systems and game engines still do this: store sin(θ) for, say, 1,024 evenly spaced angles, and interpolate.
It's fast but uses memory and has limited accuracy. You can browse a printed-style version in the trigonometric tables.
An Insider Reference: When the Error Bounds Were Wrong
In 2014, software developer Bruce Dawson published a detailed investigation of the x87 FSIN instruction found in Intel processors. Intel's documentation had claimed very high accuracy. Dawson showed that near multiples of π, the results could be far less accurate than advertised, in the worst cases correct to only a few significant digits.
The cause was the value of π used internally: a 66-bit approximation. Near π, where sin x is very close to zero, that small approximation error dominated the result. Intel updated its documentation after the findings.
Most modern software doesn't rely on FSIN; math libraries compute trig functions in software, often with correctly rounded results. But the episode is a reminder that "how the computer calculates sine" is a genuine engineering problem, not a solved detail.
An Ancient Shortcut
In the 7th century, Indian mathematician Bhāskara I gave a remarkable rational approximation of sine, using angles in degrees:
sin x° ≈ 4x(180 − x) / (40,500 − x(180 − x))
At x = 30, it gives 4 × 30 × 150 / (40,500 − 4,500) = 18,000 / 36,000 = 0.5, exactly right. Across 0° to 180°, it's never off by more than about 0.0016, remarkable for an approximation with no calculus at all. Compare with the sine calculator.
Two Concepts Worth Knowing
Radians
Taylor series only take their simple form when angles are in radians, where a full circle is 2π. That's why programming languages' sin() functions expect radians, not degrees.
Periodic Function
A periodic function repeats at regular intervals. Sine and cosine repeat every 2π radians, which is what lets computers reduce any angle to a small range before calculating.
Quick Answer: How Do Computers Calculate Sine and Cosine?
Computers first use symmetry to reduce the angle to a small range like 0 to 45°. Software libraries then evaluate carefully designed polynomial approximations based on Taylor series. Simple hardware often uses CORDIC, which rotates a vector through a sequence of known angles using only additions and binary shifts.
Try Them Yourself
- Sine Calculator: compare with your Taylor series results
- Cosine Calculator: check the co-function identity
- Arc Tangent Calculator: the CORDIC angle table
- Reference Angle Calculator: fold any angle into the first quadrant
- Trigonometric Tables: the lookup-table approach
- Trigonometric Formulas: identities behind angle reduction
Compute sin(20°) with three Taylor series terms using a basic calculator. Then check it with the sine calculator and count how many digits you got right.