The math.deg function converts the angle, in radians, represented by the argument, to its equivalent in degrees. It accepts both integers and floats, positive or negative.

Syntax

math.deg(`x`)

Parameters

  • Name
    x
    Type
    number
    Description

    A number representing an angle in radians.

Return Value

The equivalent angle in degrees. When x is not a number, the function is aborted with the error bad argument #1 to 'deg' (number expected, got <data_type>), where data_type is the type of the object passed as argument to the function.

Examples

Using math.deg

print(math.deg(2))           -- Output: 114.5915...
print(math.deg(-4))          -- Output: -229.1831...
print(math.deg(1.54))        -- Output: 88.2355...
print(math.deg(0.000000007)) -- Output: 4.0107045659158e-07

Special cases

print(math.deg(math.huge))  -- Output: Inf (positive infinity)
print(math.deg(-math.huge)) -- Output: -Inf (negative infinity)

Use Cases

  • Graphics manipulation: useful for calculating rotation of textures/shapes.

See also

  • math.log(): Calculates the natural logarithm of a number, the inverse of math.exp().
  • math.pow(): Computes the result of raising any base to a power.
  • math.sqrt(): Computes the square root of a number, useful for related calculations.

Was this page helpful?

Table of Contents