Hypot()
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 contributor
Contribute to Docs
- 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.
Learn Go on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Go
Learn how to use Go (Golang), an open-source programming language supported by Google!Beginner Friendly6 hours