Skip to main content

sqrt

Function sqrt 

Source
pub fn sqrt(x: number) -> number
Expand description

Returns the square root of a number.

§Parameters

  • x: a number greater than or equal to 0.

§Return value

The square root of x, as a nonnegative float. If x is less than 0, the result is NaN.

§Description

You can also use the expression x^0.5 to compute this value. Like all Lua functions, sqrt lives in a table (the math library), so it is called as math.sqrt(x).

§Examples

print(math.sqrt(0))          --> 0.0
print(math.sqrt(1))          --> 1.0
print(math.sqrt(2))          --> 1.4142135623730951
print(math.sqrt(9))          --> 3.0
print(math.sqrt(16))         --> 4.0
print(math.sqrt(-1))         --> nan
print(math.sqrt(math.huge))  --> inf

§See also

exp, log