Hypot()
Anonymous contributor
Anonymous contributor1 total contribution
Anonymous contributor
Published Aug 22, 2023
Contribute to Docs
The Hypot()
function returns the square root of the sum of two squares. In other words, the method returns the result of the following formula:
Syntax
import math
result := math.Hypot(x, y)
Hypot()
accepts two arguments (x
, y
) of type float64
and returns a value of type float64
.
Note:
- If either argument is negative, or both, the result is positive.
- If either argument is positive infinity (
+Inf
), the result will be positive infinity. - If
0
is passed as both arguments, the result is0
. If one of the arguments is0
the result is equal to the other argument. - If either argument passed is
NaN
, the result will beNaN
.
Example
package mainimport("fmt""math")func main() {fmt.Printf("Hypotenuse of 3 and 4 = %f\n", math.Hypot(3 , 4))fmt.Printf("Hypotenuse of -1.5 and -1.5 = %f\n", math.Hypot(-1.5,-1.5))}
The above example results in the following output:
Hypotenuse of 3 and 4 = 5.000000Hypotenuse of -1.5 and -1.5 = 2.121320
Codebyte Example
The runnable example of the Hypot()
function of the cases where 0
or a negative number is at least one of the arguments.
All contributors
- Anonymous contributorAnonymous contributor1 total contribution
- Anonymous contributor
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.