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.


sqrt() function is implemented with the following syntax:


Where the num_var is a positive number.

Example 1

The function returns the square root of 25.

num_var = 25

The code returns the following output:


Example 2

The code below demonstrates the method with a negative value.

num_var = -25

The results will look like this:


Where nan stands for “not a number”, which represent undefined or unpresentable numerical results.

All contributors

Looking to contribute?

Learn Lua on Codecademy