math.sqrt
Defined in module
"math"from "math" import sqrtReturns the square root of x
Parameters
x | number | the 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
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)) = floatSee also
pow | Returns x raised to the power y |
exp | Returns e raised to the power of x |
| math | module index |