...
Source file
src/math/hypot.go
Documentation: math
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
29 switch {
30 case IsInf(p, 0) || IsInf(q, 0):
31 return Inf(1)
32 case IsNaN(p) || IsNaN(q):
33 return NaN()
34 }
35 p, q = Abs(p), Abs(q)
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