Sqrt()
Anonymous contributor
Anonymous contributor2 total contributions
Anonymous contributor
Published Jul 18, 2023Updated Jul 28, 2023
Contribute to Docs
The Sqrt()
function returns the square root of a given number.
Syntax
import math
sqrt = math.Sqrt(x)
Sqrt()
accepts an argument of type float64
and returns a value of type float64
.
Note these special cases:
- The result of calling
Sqrt()
with a negative number isNaN
. - If
0
is passed as the argument the result is0
. - Passing
+Inf
toSqrt()
results in+Inf
. - If
Sqrt()
is called withNaN
as the argument the result isNan
.
Example
package mainimport ("fmt""math")func main() {fmt.Printf("Square root of 9 = %f\n", math.Sqrt(9))fmt.Printf("Square root of 12.5 = %f\n", math.Sqrt(12.5))}
The above code results in the following output:
Square root of 9 = 3.000000Square root of 12.5 = 3.535534
Codebyte Example
The runnable example demonstrates the output of Sqrt()
in the special cases where 0
or a negative number are supplied as arguments.
All contributors
- Anonymous contributorAnonymous contributor2 total contributions
- clodaghw174 total contributions
- Anonymous contributor
- clodaghw17
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.