GoLang – Find Square Root – Sqrt() Function – Examples & Explanation

Sqrt() function is used to find the square root of the given input (x – parameter) in Go language. The standard math package of Go programming language has Sqrt() function.

Syntax of Sqrt() Function in Go Language

The syntax of Sqrt() function in Go Language is:

Note: float64 is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Sqrt(+Inf) = +Inf
Sqrt(±0) = ±0
Sqrt(x < 0) = NaN
Sqrt(NaN) = NaN


Parameters of Sqrt() Function in Go Language

x – where x is any Valid float64 Input value. This parameter is required.


Error Handling

If the x parameter is not a number (numeric value) Sqrt() function returns an error .
If there is no argument (x – input value) passes to the function, then the compiler will produce an error.


Return Value of Sqrt() Function in GoLang

Sqrt() function will return the square root of the given input(x – parameter).


GoLang Sqrt() Function Example 1



GoLang Sqrt() Function Example 2



GoLang Sqrt() Function Example 3