1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 Hypot -- sqrt(p*p + q*q), but overflows only if the result does.
11 // Hypot returns [Sqrt](p*p + q*q), taking care to avoid
12 // unnecessary overflow and underflow.
16 // Hypot(±Inf, q) = +Inf
17 // Hypot(p, ±Inf) = +Inf
18 // Hypot(NaN, q) = NaN
19 // Hypot(p, NaN) = NaN
20 func Hypot(p, q float64) float64 {
22 return archHypot(p, q)
27 func hypot(p, q float64) float64 {
31 case IsInf(p, 1) || IsInf(q, 1):
33 case IsNaN(p) || IsNaN(q):
43 return p * Sqrt(1+q*q)