sqrt()
Published Oct 28, 2023
Contribute to Docs
The math.sqrt() function returns the result of the square root operation on a numeric variable. It takes a positive number as an argument value to be passed into the function.
Note: Results are dependent on the compiler. There may be a small variation or results may not be as precise as expected.
Syntax
sqrt()
function is implemented with the following syntax:
math.sqrt(num_var)
Where the num_var
is a positive number.
Example 1
The function returns the square root of 25
.
num_var = 25print(math.sqrt(num_var))
The code returns the following output:
5.0
Example 2
The code below demonstrates the method with a negative value.
num_var = -25print(math.sqrt(num_var))
The results will look like this:
nan
Where nan
stands for “not a number”, which represent undefined or unpresentable numerical results.
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
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Lua
Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.Beginner Friendly4 hours