Source file
src/math/hypot.go
1
2
3
4
5 package math
6
7
10
11
12
13
14
15
16
17
18
19
20 func Hypot(p, q float64) float64 {
21 if haveArchHypot {
22 return archHypot(p, q)
23 }
24 return hypot(p, q)
25 }
26
27 func hypot(p, q float64) float64 {
28 p, q = Abs(p), Abs(q)
29
30 switch {
31 case IsInf(p, 1) || IsInf(q, 1):
32 return Inf(1)
33 case IsNaN(p) || IsNaN(q):
34 return NaN()
35 }
36 if p < q {
37 p, q = q, p
38 }
39 if p == 0 {
40 return 0
41 }
42 q = q / p
43 return p * Sqrt(1+q*q)
44 }
45
View as plain text