1
// Copyright 2009-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.
10
Cleve Moler and Donald Morrison,
11
Replacing Square Roots by Pythagorean Sums
12
IBM Journal of Research and Development,
13
Vol. 27, Number 6, pp. 577-581, Nov. 1983
16
// Hypot computes Sqrt(p*p + q*q), taking care to avoid
17
// unnecessary overflow and underflow.
20
// Hypot(p, q) = +Inf if p or q is infinite
21
// Hypot(p, q) = NaN if p or q is NaN
22
func hypotGo(p, q float64) float64 {
23
// TODO(rsc): Remove manual inlining of IsNaN, IsInf
24
// when compiler does it for us
27
case p < -MaxFloat64 || p > MaxFloat64 || q < -MaxFloat64 || q > MaxFloat64: // IsInf(p, 0) || IsInf(q, 0):
29
case p != p || q != q: // IsNaN(p) || IsNaN(q):