Trigonometric functions take angles as input — but whether that input should be in degrees or radians depends entirely on which function implementation you're calling, and passing degrees to a radian-expecting function is a silent, frequently-made error that produces wrong answers without any error message
The previous articles on this site covered angle unit basics, navigation/GPS angles, construction gradients, and CSS rotation conventions. This article addresses angle units in programming — specifically why radians are the native unit for mathematics and virtually all programming language math libraries, and the common bugs that occur when developers confuse degrees and radians.
Why radians are the "natural" unit for trigonometry
The radian is defined geometrically: one radian is the angle subtended at the center of a circle by an arc equal in length to the radius. A full circle (360°) = 2π radians ≈ 6.283 radians.
Why this makes radians "natural" in mathematics: when angles are in radians, the derivatives of trigonometric functions have the cleanest possible form:
- d/dx(sin x) = cos x
- d/dx(cos x) = −sin x
If angles were in degrees, these derivatives would require a π/180 correction factor:
- d/dx(sin x°) = (π/180) cos x°
This means: for calculus, Fourier analysis, physics, signal processing, and any math involving derivatives of trig functions — radians are the natural unit, and formulas written in radians have no conversion factors. Every programming language math library uses radians by default precisely because the underlying mathematics is cleaner in radians.
The most common degree/radian bug in code
// Wrong: passing degrees to a radian-expecting function
const angle = 45; // degrees
const sine = Math.sin(angle); // Math.sin expects RADIANS
// Result: Math.sin(45) = 0.8509 (sine of 45 radians ≈ 2578°)
// Expected: Math.sin(π/4) = 0.7071 (sine of 45°)
The bug: Math.sin(45) doesn't error — it computes the sine of 45 radians, which is a valid but almost certainly unintended calculation. 45 radians is equivalent to approximately 2578 degrees, wrapped around the unit circle multiple times. The result (0.8509) is a valid sine value — there's nothing mathematically wrong — it's just completely wrong for the intended calculation.
The correct code:
const degreesToRadians = angle => angle * Math.PI / 180;
const sine = Math.sin(degreesToRadians(45)); // 0.7071 ✓
Why this bug is so persistent: Math.sin(degrees) produces a plausible-looking number — it doesn't return NaN, it doesn't throw an error, it doesn't return a value outside [-1, 1]. The incorrect result silently propagates through calculations until something looks wrong visually or numerically — at which point the degree/radian confusion may not be obvious as the root cause.
Every major language's math library: radians by default
Python:
import math
math.sin(math.radians(45)) # Correct: convert first
math.sin(45) # Wrong: 45 radians
JavaScript/TypeScript:
Math.sin(45 * Math.PI / 180) // Correct
Math.sin(45) // Wrong
Java:
Math.sin(Math.toRadians(45)) // Correct
Math.sin(45) // Wrong
C/C++:
#include <math.h>
sin(45.0 * M_PI / 180.0) // Correct
sin(45.0) // Wrong
The pattern is universal: the built-in math libraries use radians, and conversion is always the programmer's responsibility. There is no mainstream language where sin(45) means "sine of 45 degrees" in the built-in math library.
Notable angle bugs in real software
The space-related context: angle calculation bugs have contributed to problems in aerospace simulations, flight guidance systems, and game physics engines — domains where trigonometric calculations are foundational and a degree/radian error silently produces systematically wrong trajectories or rotations.
Game development: 3D game engines typically use radians in their math APIs (OpenGL, DirectX, Vulkan all work in radians for rotation matrices) — but artists often think in degrees, and interfaces may convert silently. A rotation that looks correct in a debug view at small angles can accumulate large errors at full rotation because a degree/radian confusion produces the right-ish answer near 0 but diverges at larger values.
Spreadsheets: Excel's SIN(), COS(), TAN() functions take radians by default — a source of confusion for non-programmers who expect degrees. Excel does provide DEGREES() and RADIANS() conversion functions, and some users discover the issue only when their formula produces unexpected results. Google Sheets follows the same convention.
The inverse functions: atan, atan2, asin, acos also return radians
Inverse trigonometric functions (arcsine, arccosine, arctangent) return angles in radians — the same library that expects radians as input also returns radians as output:
Math.atan2(1, 1) // Returns 0.7854 radians (= π/4 = 45°)
Math.atan2(1, 1) * 180 / Math.PI // 45° ✓
atan2 specifically — the two-argument arctangent that handles all four quadrants correctly — is one of the most useful functions in computer graphics, navigation, and physics. Its output in radians needs to be converted to degrees for any human-facing angle display.
How to use the Angle Converter on sadiqbd.com
- Before plugging values into code: convert your degree angles to radians using this tool — then verify the radian value looks correct (45° → 0.7854 rad, 90° → 1.5708 rad, 180° → 3.1416 rad, 360° → 6.2832 rad)
- After getting radian output from code (atan2, etc.): convert back to degrees to understand what the angle actually is in human terms
- As a sanity check on code: if your trigonometric calculation produces unexpectedly large or small values, check whether degree/radian confusion is the cause — compute what the function should return for a known input, compare against what it actually returns, and if they differ by a factor related to π/180, you've found the bug
Frequently Asked Questions
Are there any languages or libraries where trigonometric functions use degrees by default?
Very few. Some domain-specific languages and specialized tools (certain CAD/surveying software, some calculator APIs) default to degrees, but mainstream programming languages universally use radians. Some languages provide degree-variants alongside radian-variants (e.g., sind() for "sine of degrees" in MATLAB/Octave, SIN() in SQL Server accepts radians but SQL Server also offers no built-in degree-mode), but these are not the standard Math.sin() / sin() / math.sin() that developers reach for by default. The safe assumption: any standard math library function takes and returns radians.
Is the Angle Converter free? Yes — completely free, no sign-up required.
Try the Angle Converter free at sadiqbd.com — convert between degrees, radians, gradians, and arcminutes/arcseconds instantly.