Source File
hypot.go
Belonging Package
math
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package math
/*
Hypot -- sqrt(p*p + q*q), but overflows only if the result does.
*/
// Hypot returns Sqrt(p*p + q*q), taking care to avoid
// unnecessary overflow and underflow.
//
// Special cases are:
// Hypot(±Inf, q) = +Inf
// Hypot(p, ±Inf) = +Inf
// Hypot(NaN, q) = NaN
// Hypot(p, NaN) = NaN
func (, float64) float64
func (, float64) float64 {
// special cases
switch {
case IsInf(, 0) || IsInf(, 0):
return Inf(1)
case IsNaN() || IsNaN():
return NaN()
}
, = Abs(), Abs()
if < {
, = ,
}
if == 0 {
return 0
}
= /
return * Sqrt(1+*)
}