Quirrel4.41.0

math.sqrt

Defined in module "math"
from "math" import sqrt
pure fastcall sqrt(x: number): float

Returns the square root of x

Parameters

xnumberthe number to take the square root of

Return value

The square root of x, as a float.

Notes

The result is always a float, even when x is an integer: type(sqrt(4)) is "float".

A negative x does not throw. It returns NaN, and NaN prints differently between compilers and platforms, so do not print it from portable code.

Example

examples/math/sqrt.nut
from "math" import sqrt

println("sqrt(2) =", sqrt(2))
println("sqrt(9) =", sqrt(9))

// the result is a float even when x is an integer
println("type(sqrt(4)) =", type(sqrt(4)))
Output:
sqrt(2) = 1.41421
sqrt(9) = 3
type(sqrt(4)) = float

See also

powReturns x raised to the power y
expReturns e raised to the power of x
mathmodule index