deg()
Lua’s math.deg()
function takes an angle in radians as input and returns the equivalent angle in degrees. This function is helpful when working with angles in a more human-readable and familiar unit, especially for tasks like user interfaces or displaying angles in degrees rather than radians.
Note: It’s important to be cautious of rounding errors when converting between degrees and radians due to computer’s floating-point representation, especially for small or large angles. Rounding errors occur when converting between degrees and radians due to the inherent limitations of number representations.
Syntax
The math.deg()
function must be called with an argument using the following syntax:
math.deg(x)
- Where
x
is a number representing an angle in radians to be convert to degrees. If no argument is passed, the program will raise an error.
Example
The following example shows the basic use of math.deg()
:
local angleInRadians = math.pi / 4local angleInDegrees = math.deg(angleInRadians)print("The angle in degrees equals: " .. angleInDegrees)
The above example results in the following output:
The angle in degrees equals: 45.0
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.