1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
func myPow(x float64, n int) float64 {
switch {
case n == 0:
return float64(1)
case n == 1:
return x
case n < 0:
return 1 / myPow(x, -n)
}
if n&1 == 0 {
return myPow(x*x, n>>1)
} else {
return myPow(x*x, n>>1) * x
}
}
|