math.sqrt
Shared
Returns the square root of a number
Syntax
local result = math.sqrt(
value
)Parameters
| Type | Name | Description |
|---|---|---|
number | value | Non-negative number to take the square root of |
Returns
| Type | Name | Description |
|---|---|---|
number | result | Square root of value |
Examples
local result = math.sqrt(9)
engine.print("info", result) -- 3.0local result = math.sqrt(2)
engine.print("info", result) -- 1.4142135623731local result = math.sqrt(0)
engine.print("info", result) -- 0.0local result = math.sqrt(1000000)
engine.print("info", result) -- 1000.0local dx = 3
local dy = 4
local distance = math.sqrt(dx * dx + dy * dy)
engine.print("info", distance) -- 5.0local vx, vy = 6, 8
local length = math.sqrt(vx * vx + vy * vy)
local nx, ny = vx / length, vy / length
engine.print("info", nx, ny) -- 0.6 0.8local px, py = 3, 3
local radius = 5
local dist = math.sqrt(px * px + py * py)
if dist <= radius then
engine.print("info", "Inside radius")
end