math.Hypot Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the hypotenuse, i.e., Sqrt(a*a + b*b) with the help of Hypot() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to access the Hypot() function.
func Hypot(a, b float64) float64
- If you pass +Inf or -Inf in this function like Hypot(+Inf, b) or Hypot(-Inf, b), then this function will return +Inf.
- If you pass +Inf or -Inf in this function like Hypot(a, +Inf) or Hypot(a, -Inf), then this function will return -Inf.
- If you pass NaN in this function like Hypot(NaN, b) or Hypot(a, NaN), then this function will return NaN.
Result 1: 5.0 Result 2: 6.3 Result 3: +Inf Result 4: NaN
5.00000 + 6.32456 = 11.32456