cos()

ElMurimi's avatar
Published Oct 26, 2023
Contribute to Docs

The cos() function returns the cosine of an angle given in radians.

Syntax

$result = math.cos(angle);

result: The variable to store the output of the cosine operation. angle: The angle in radians.

Example

The example below demonstrates the use of the math.cos() function to find the cosine of a 45-degree angle.

local angle = (math.pi / 4) -- 45 degrees in radians
local cosineOutput = math.cos(angle)
print(cosineOutput)

This example will result in the following output:

0.70710678118655

All contributors

Contribute to Docs

Learn Lua on Codecademy