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 func Hypot(p, q float64) float64 {
20 if haveArchHypot {
21 return archHypot(p, q)
22 }
23 return hypot(p, q)
24 }
25
26 func hypot(p, q float64) float64 {
27
28 switch {
29 case IsInf(p, 0) || IsInf(q, 0):
30 return Inf(1)
31 case IsNaN(p) || IsNaN(q):
32 return NaN()
33 }
34 p, q = Abs(p), Abs(q)
35 if p < q {
36 p, q = q, p
37 }
38 if p == 0 {
39 return 0
40 }
41 q = q / p
42 return p * Sqrt(1+q*q)
43 }
44
View as plain text