Lua tan()
Published Oct 14, 2023
Contribute to Docs
In Lua, the math.tan() function is a standard mathematical function that is part of the Lua math library. It is used to calculate the tangent of a given angle.
Note:
math.tan()expects the input angle value to be in radians. If an angle’s value is in degrees, it can be converted into radians using themath.piconstant in Lua and the following formula:radians = degrees * (math.pi / 180)
Syntax
math.tan(myangle)
Example
To find the tangent of an angle in degrees, first convert it into radians, and then pass the value to the math.tan() function, or simply pass in the radian value:
local angle = 45 * ( math.pi / 180 )print(math.tan(angle))print(math.tan(math.pi / 6))
This results in the following output:
1.00.57735026918963
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.
Learn Lua on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
- Beginner Friendly.4 hours