Understanding Angle Measurement Systems
An angle can be described using degrees or radians.
Try it: The math Module: Logs, Roots and Angles
What math.log(x), math.log10(x), math.log(x, base), math.sqrt(x) and math.sin / cos / tan really compute: which logarithm base each call uses, why 0 and negative inputs must be checked before the call (ValueError: math domain error), why trigonometric functions need radians, and that math.pi and every result are binary64 approximations (math.log(1000, 10) prints 2.9999999999999996).
How it works
- math.log(x) is the natural logarithm (base e); math.log10(x) is base 10; math.log(x, base) computes log(x) / log(base) with two rounded natural logs.
- Logarithms need x > 0 and math.sqrt needs x >= 0; otherwise the call raises ValueError: math domain error, so a guard checks the input first.
- math.sin, math.cos and math.tan read their argument as radians: convert degrees with degrees / 360.0 * 2 * math.pi.
- math.pi is a float value (no parentheses) that approximates pi to about 16 digits, so sin(180 degrees) is 1.2246467991473532e-16, not 0.
- Every result is the nearest binary64 value; print shows the shortest repr that reads back as the same float, while the stored value has more digits.
Default run (6 steps): Ready: the program calls math.log10(x). … print(result) shows 3.0.
Simplified: One-call programs over int / float literals you type (|x| up to 1e15). The results come from the browser's IEEE-754 math library: math.sqrt and the radians arithmetic are identical to CPython; log / sin / cos / tan match CPython 3.12 (Windows) exactly for about 91% of the tested inputs and are within 2 units in the last place otherwise, because C math libraries differ in the last bit. Error messages are CPython 3.12's (3.14 says 'expected a positive input').
Loading the simulation…
Why Units Matter
An angle can be described using degrees or radians. These are different measurement systems for angles, not different angles themselves. Python's trigonometric functions, including sin, cos, and tan, expect their arguments in radians. If you pass a degree value directly, Python interprets that number as radians and produces an incorrect result for the degree-based intention.
The number 45 does not automatically mean 45 degrees when it is given to Python's math.sin, math.cos, or math.tan. Without conversion, Python treats it as 45 radians.
Scaling Degrees into Radians
The conversion follows the relationship between a full turn in the two systems: a full circle is 360 degrees and also 2π radians. To convert any degree measurement, first express it as a fraction of 360 degrees, then scale that fraction by 2π radians.
- 1Start with the degree measurement.
- 2Divide by 360.0 to find the measurement's fraction of a full circle.
- 3Multiply by 2 *
math.pibecause a full circle is 2π radians. - 4Use the resulting value as the argument to the trigonometric function.
The Role of math.pi
math.pi is Python's representation of π. It is provided by the math module and is accurate to about 15 decimal places, making it suitable for practical calculations.
The conversion formula uses math.pi because the radian measurement of a full circle is 2π. Using math.pi avoids replacing π with a short hardcoded approximation such as 3.14159. The source material describes math.pi as the most accurate representation of π available in Python without external libraries.
Tracing a 45-Degree Calculation
Converting 45 Degrees Before Finding Its Sine
Find the sine of a 45-degree angle using Python's radian-based trigonometric function.
- 1Start with the degree value
The angle is 45 degrees.
- 2Apply the conversion
Calculate 45 / 360.0 * 2 *
math.pi. This gives approximately 0.785 radians. - 3Pass radians to the function
Give the converted value to
math.sinrather than passing 45 directly. - 4Interpret the result
The resulting sine is approximately 0.707, the mathematically correct sine of 45 degrees.
The correct process is to convert 45 degrees to approximately 0.785 radians and then calculate its sine, which is approximately 0.707.
approximately 0.785 radians
approximately 0.707The variable name radians makes the unit change visible in the calculation. After conversion, the value passed to math.sin represents radians, which is the unit that Python's trigonometric function expects.
What Python Receives
What do you think happens?
If you want the sine of 45 degrees, what should be passed to math.sin?
Reveal answer
45 converted to approximately 0.785 radians
Python's trigonometric functions require radian arguments. Passing 45 directly makes Python interpret the value as 45 radians rather than 45 degrees.
Correcting Unit Mix-Ups
Common mistake Passing a degree value directly to math.sin, math.cos, or math.tan
What it looks likemath.sin(45)Why it failsPython interprets 45 as 45 radians, not 45 degrees.
Do this insteadConvert the degree value first, then pass the radian result to the function.
Common mistake Treating the conversion as optional because the number is an angle
What it looks likeUsing a variable named angle without recording whether it contains degrees or radians
Why it failsThe trigonometric function requires a specific unit: radians.
Do this insteadUse a clear name such as degrees or radians and convert before the function call.
Common mistake Replacing math.pi with a short hardcoded approximation
What it looks likeUsing 3.14159 in place of math.pi
Why it failsA short approximation provides less precision than Python's
math.pi.Do this insteadUse math.pi in the conversion formula.
import math
sine_value = math.sin(45)The value 45 is passed directly, so Python interprets it as radians.
import math
degrees = 45
radians = degrees / 360.0 * 2 * math.pi
sine_value = math.sin(radians)The degree value is converted to radians before it is passed to math.sin.
A Reliable Calculation Routine
- 1Decide whether the original measurement is in degrees.
- 2Store or identify the degree value clearly.
- 3Convert it with degrees / 360.0 * 2 *
math.pi. - 4Pass the converted radians value to sin, cos, or tan.
- 5Check that the result is based on the intended angle measurement system.
Treat the unit as part of the value. A number such as 45 is incomplete for this task unless you know whether it means 45 degrees or 45 radians. Naming variables according to their units makes the conversion step easier to see and reduces the chance of passing the wrong measurement to a trigonometric function.
Practice the Conversion
Write the steps needed to calculate the sine of a 90-degree angle in Python. Identify the value that should be passed to the trigonometric function and explain why passing 90 directly would be incorrect.
Hints
- Begin with degrees = 90.
- Apply degrees / 360.0 * 2 *
math.pi. - Pass the converted result to
math.sin, not the original degree value.
Inspect this calculation: math.cos(180). What unit does Python interpret the argument as? Rewrite the calculation so that 180 is treated as degrees.
Hints
- Python's math trigonometric functions expect radians.
- Use the degree-to-radian formula and
math.pibefore callingmath.cos.
Key Takeaways
- 1Python's sin, cos, tan, and other math-module trigonometric functions require radians.
- 2A full circle is 360 degrees or 2π radians.
- 3Convert degrees with radians = degrees / 360.0 * 2 *
math.pi. - 4Use
math.pifor an accurate representation of π. - 5Passing degrees directly makes Python interpret them as radians and produces an incorrect result for the intended degree measurement.
At a glance
- Python's trigonometric functions require radian arguments, not degree arguments.
- Convert a degree measurement by dividing by 360.0 and multiplying by 2 *
math.pi. - Use
math.piinstead of a short hardcoded approximation of π. - Passing a degree value directly causes Python to interpret that value as radians.